Creating an API¶
Follow the instructions given below to create a new REST API artifact in WSO2 Integration Studio.
Step 1: Create new API¶
Right-click the project in the navigator and go to New → REST API to open the API Artifact Creation Options dialog box.
Select the Create A New API Artifact and click Next.
Specify values for the required REST API properties: API name, and Context.
Do one of the following to save the API:
- To save the API in an existing ESB Config project in your workspace, click Browse and select that project.
- To save the API in a new ESB Config project, click Create new Project and create the new project.
- Click Finish. The REST API is created inside the
src/main/synapse-config/apifolder under the ESB Config project you specified.
Open the new artifact from the project explorer. Select the Design View to view the API artifact with the default Resource.
Click the API to open the Properties tab and update any optional REST API properties.
Step 2: Add new API Resources (Optional)¶
When you created the API, an API resource is created by default. If you want to add a new resource, click API Resource in the Tool pallet of the API section and simply drag and drop the resource to the REST API.
About the default API Resource
Each API can have at most one default resource. Any request received by the API but does not match any of the enclosed resource definitions will be dispatched to the default resource of the API. In case of API_3, a DELETE request on the URL “/payments” will be dispatched to the default resource as none of the other resources in API_3 are configured to handle DELETE requests. If you go to the Source view, the default resource will be as follows:
<api context="/healthcare" name="HealthcareAPI" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET"> <inSequence/> <outSequence/> <faultSequence/> </resource> </api>
Step 3: Update API Resource Properties¶
Open the REST API artifact and go to the Design view of the API Resource, click the Resource icon to enable the Properties tab.
You can now update the API Resource properties.
- Using a Simple Rest API
- Working with Query Parameters
- Exposing a SOAP Endpoint as a RESTful API
- Exposing Non-HTTP Services as RESTful APIs
- Handling Non Matching Resources
- Handling HTTP Status Codes
- Manipulating Content Types
- Securing a REST API
- Using GET with a Message Body
- Using POST with Empty Message Body
- Using POST with Query Parameters