A REST API in WSO2 Micro Integrator is analogous to a web application deployed in the web container. Each API is anchored at a user-defined URL context, much like how a web application deployed in a servlet container is anchored at a fixed URL context. An API will only process requests that fall under its URL context. An API is made of one or more Resources, which are logical components of an API that can be accessed by making a particular type of HTTP call.
A REST API resource is used by the Micro Integrator to process messages before forwarding them to the relevant endpoint. Just as Proxy Services and Inbound Endpoints, the REST API resource uses mediators and sequences to define the mediation logic for processing messages. The API resource mediates incoming requests, forwards them to a specified endpoint, mediates the responses from the endpoint, and sends the responses back to the client that originally requested them. The In sequence handles incoming requests and sends them to the back-end service, and the Out sequence handles the responses from the back-end service and sends them to the requesting client. You can also define a fault sequence to handle any errors that may occur while mediating a message through a resource.
We can create an API resource to process defined HTTP request methods. Furthermore, you can configure REST endpoints in an API by directly specifying HTTP verbs (such as POST and GET), URI templates, and URL mappings. Alternatively, you can use the HTTP Endpoint to define REST endpoints using URI templates.
See the topics given below for the list of properties that can be configured when creating a REST API artifact.
REST API Properties (Required)¶
The following properties are required in order to create the REST API artifact.
|Name||A unique name for the new API.|
An API in WSO2 Micro Integrator is analogous to a web application deployed in the Micro Integrator. Each API is anchored at a user-defined URL context, much like how a web application deployed in a servlet container is anchored at a fixed URL context. An API only processes requests that fall under its URL context. For example, if a particular API is anchored at the context
REST API Properties (Optional)¶
The following properties are optional properties you can configure when creating a REST API artifact.
|Hostname||The Host at which the API is anchored. If you do not enter a value,
|Port||The Port of the REST API. If you do not enter a value,
|Version||The Micro Integrator identifies each API by its unique context name. If you introduce a version in the API context (e.g., /Service 1.0.0), you can update it when you upgrade the same API (e.g., /Service 1.0.1). Version your APIs as early as possible in the development cycle.|
REST API Resource Properties¶
|URI Style||This allows us to restrict the type of HTTP requests processed by a particular resource. A resource can be associated with a user-defined URL mapping or a URI template.|
This property is enabled only if URI Template is specified as the URI Style.
A URI template represents a class of URIs using patterns and variables. When a resource is associated with a URI template, all requests that match the template will be processed by the resource. Some examples of valid URI templates are as follows:
This property is enabled only if URL Mapping is specified as the URI Style.
When a resource is defined with a URL mapping, only those requests that match the given pattern will be processed by the resource. There are three types of URL mappings:
|Protocol||Specify the HTTP methods that the resource should handle. This provides additional control over what requests are handled by a given resource.|