Exposing a RESTful resource using the HTTP connector icon

Exposing a RESTful resource using the HTTP connector

(0 reviews)

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.

  1. Create, then run the example application in Anypoint Studio or Standalone.
  2. 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"
         }
     }
  3. You should recieve a response saying a person was created successfully:

     { "status": "success", "statusDescription": "person created successfully"}
  4. Send a GET request to http://localhost:8081/person/1
  5. 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}
  6. Send a GET request to http://localhost:8081/person

  7. 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.

Documentation

Read full documentation in GitHub


Reviews

TypeExample
OrganizationMulesoft Inc.
Published by
MuleSoft Organization
Published onMar 17, 2018
Asset overview

Asset versions for 1.4.x

Asset versions
VersionActions
1.4.0