Evaluation and validation of application programming interface requests and responses for microservices applications
A method for evaluating and validating requests before they reach one or more services in a microservice application, each service being an application program interface (API) performing a piecemeal function of an overall application function, including receiving an API message and comparing the body thereof to a schema; based on that comparison either forwarding the message on as normal in the event of a successful comparison and generating an error message when the comparison fails. In some embodiments, the schema implements Open API Specification Validation.
1 . A method of evaluating and validating a request to a service of a plurality of services that form a microservices architecture application, each of the plurality of services being an application program interface (API) performing a piecemeal function of an overall application function, the method being implemented in a service extension, and the method comprising:
receiving, from a client, the request comprising a request body, wherein the request is intercepted before reaching the service;
retrieving a configuration of the service extension, the configuration comprising an identifier for the service, a Boolean flag indicative of the service extension being enabled or disabled, a specification of a reference schema, an identifier of a validator that is configured to generate a Boolean result, and a set of parameters for the validator;
generating, by the validator identified in the configuration and using the set of parameters for the validator, the Boolean result indicative of a schema of the request body being identical to the reference schema associated with a configuration of the service extension, wherein generating the Boolean result comprises comparing a type of each parameter of the request body to a type of each corresponding parameter in the reference schema;
and
upon a determination that the Boolean result is false, transmitting, to the client, a message indicative of an error in the request, wherein the request is prevented from reaching the service.
2 . The method of claim 1 , wherein the schema of the request body comprises a first set of parameters, wherein the reference schema comprises a second set of parameters, and wherein generating the Boolean result comprises:
comparing a type of each parameter of the first set of parameters to the type of each corresponding parameter in the second set of parameters.
3 . The method of claim 1 , wherein the service extension is a plugin.
4 . The method of claim 1 , wherein the service extension is a browser extension.
5 . The method of claim 1 , wherein the validator is a Kong schema validator or a validator compliant with a schema definition language for describing a structure and validation constraints of data objects.
6 . The method of claim 1 , wherein the Boolean result is further indicative of a value of a parameter of the schema of the request body being semantically identical to a value of a corresponding parameter of the reference schema.
7 . A system comprising:
one or more processors;
a memory including instructions, that when executed by the one or more processors, cause implementation of a microservice architecture application comprising a plurality of services that interact to perform an overall application function, each of the plurality of services being an application program interface (API) performing a piecemeal function of the overall application function; and
execution of the instructions by the one or more processors further cause the implementation of a plugin,
wherein the plugin is enabled for an object associated with the microservice architecture application, and wherein the plugin is configured to:
receive a message comprising a message body, wherein the message is intercepted before reaching a service of the plurality of services,
retrieve a configuration of the plugin, the configuration comprising an identifier for the service, a Boolean flag indicative of the plugin being enabled or disabled, a specification of a reference schema, an identifier of a validator that is configured to generate a Boolean result, and a set of parameters for the validator;
generate, by the validator identified in the configuration and using the set of parameters for the validator, the Boolean result indicative of a schema of the message body being identical to the reference schema associated with the configuration of the plugin, wherein generating the Boolean result comprises comparing a type of each parameter of the message body to a type of each corresponding parameter in the reference schema; and
transmit, upon a determination that the Boolean result is false, an error message indicative of an error in the message body, wherein the message is prevented from reaching the service.
8 . The system of claim 7 , wherein the object is a service of the plurality of services, a route object associated with the service, or a consumer object that is a user of the service.
9 . The system of claim 7 , wherein the message is a request to a service of the plurality of services or a response from the service.
10 . The system of claim 7 , wherein the schema of the message body comprises a first set of parameters, wherein the reference schema comprises a second set of parameters, and wherein generating said forwarding and transmitting further comprises:
comparing a type of each parameter of the first set of parameters to the type of each corresponding parameter in the second set of parameters.
11 . The system of claim 7 , wherein the plugin is a browser extension.
12 . The system of claim 7 , wherein the validator is a Kong schema validator or a validator compliant with a schema definition language for describing a structure and validation constraints of data objects.
13 . The system of claim 7 , wherein the Boolean result is further indicative of a value of a parameter of the schema of the message body being semantically identical to a value of a corresponding parameter of the reference schema.
14 . A method comprising:
linking an application program interface (API) gateway to a microservice architecture application including a plurality of services that interact to perform an overall application function, each of the plurality of services being an API performing a piecemeal function of the overall application function;
installing a plugin at the API gateway that evaluates messages received at the API gateway, wherein the plugin is enabled for an object associated with the microservice architecture application;
receiving a message at the plugin comprising a message body, wherein the message is intercepted at the API gateway before reaching a service of the plurality of services;
retrieving a configuration of the plugin, the configuration comprising an identifier for the service, a Boolean flag indicative of the plugin being enabled or disabled, a specification of a reference schema, an identifier of a validator that is configured to generate a Boolean result, and a set of parameters for the validator;
generating, by the validator identified in the configuration and using the set of parameters for the validator, the Boolean result indicative of a schema of the message body being identical to the reference schema associated with the configuration of the plugin, wherein generating the Boolean result comprises comparing a type of each parameter of the message body to a type of each corresponding parameter in the reference schema;
transmitting, upon a determination that the Boolean result is false, an error message indicative of an error in the message body, wherein the message is prevented from reaching the service.
15 . The method of claim 14 , wherein the schema of the message body comprises a first set of parameters, wherein the reference schema comprises a second set of parameters, and wherein generating said forwarding and transmitting further comprises:
comparing a type of each parameter of the first set of parameters to the type of each corresponding parameter in the second set of parameters.
16 . The method of claim 14 , wherein the plugin is a browser extension.
17 . The method of claim 14 , wherein the message is a request to a service of the plurality of services or a response from the service.