Exposing a RESTful resource using the HTTP connector
home
Illustrates how to use Mule to expose a RESTful resource using the HTTP connector. After reading this document, creating, and running the example in Mule, you should be able to leverage what you have learned to create a simple HTTP request-response application that is able to expose a RESTful resource by providing different verbs (HTTP methods) using JSON data.
Example Use Case
In this example, a user calls the Mule application by submitting a request via a REST client (that is, entering a specific URL, such as http://localhost:8081/person/1). The application receives the request and processes it based on the URL. The application is capable of retrieving and inserting the person's data.
Set Up and Run the Example
As with other examples, you can create template applications straight out of the box in Anypoint Studio. You can tweak the configurations of these use case-based examples to create your own customized applications in Mule.
Follow the procedure below to create, then run the HTTP with JSON application.
- Create, then run the example application in Anypoint Studio or Standalone.
Send a POST request to http://localhost:8081/person with the body equals to:
{ "firstname":"John", "lastname":"Doe", "age": "12", "address": { "streetAddress":"Lincoln St.", "city":"San Francisco", "state":"CA", "zipCode":"90401" } }
You should recieve a response saying a person was created successfully:
{ "status": "success", "statusDescription": "person created successfully"}
- Send a GET request to http://localhost:8081/person/1
You should recieve a response with the person data:
{"firstname":"John","lastname":"Doe","address":{"streetAddress":"Lincoln St.","city":"San Francisco","state":"CA","zipCode":"90401"},"age":12}
Send a GET request to http://localhost:8081/person
- You should recieve a response with all created persons. If you inserted only 1 person from Step 2, then you should get only that one.