Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

About the sample

A popular data format used with RESTful services is JSON. This sample contains a data service with JSON output mapping templates. Go to JSON Mapping for details on how to use JSON templates for output mapping in data service.

Building the sample

The sample data service JSONSample should be deployed using the instructions in Samples Setup.

Running the sample

The sample service can be run using any client that can do REST calls. For example, use tools such as cURL or Advanced REST Client Chrome browser extension. The HTTP header "Accept" should be set to "application/json" and also, if a JSON payload is sent to the server, the HTTP header "Content-Type" should be set to "application/json".

Service description

The service contains the following resources:

  • "offices" (method=GET) : Lists all the offices in the database. When office information is printed, all the employees that belong to an office are also printed using a nested query, which refers to the employeesInOfficeSQL query. The HTTP request sent using CURL would be as follows:

    curl -X GET -H "Accept: application/json" http://localhost:9763/services/samples/JSONSample/offices
  • "boston_customers" (method=GET) : Returns all the customers in Boston. The HTTP request sent using CURL would be as follows:

    curl -X GET -H "Accept: application/json" http://localhost:9763/services/samples/JSONSample/boston_customers
  • "employee/{employeeNumber}" (method=GET) : Returns employee information for the given employee number. The HTTP request sent using CURL would be as follows:

    curl -X GET -H "Accept: application/json" http://localhost:9763/services/samples/JSONSample/employee/1002
  • "employee" (method=POST) : Insert a new employee to the database with the given information. A sample payload saved as the employee-payload.json file, that can be used when sending the data is given below.

    {
      "_postemployee": {
        "employeeNumber" : "14001",
        "lastName": "Smith",
        "firstName": "Will",
        "email": "will@google.com",
        "salary": "15500.0"
      }
    }

    The HTTP request sent using CURL would be as follows:

    curl -X POST -H 'Accept: application/json'  -H 'Content-Type: application/json' --data "@employee-payload.json" http://localhost:9763/services/samples/JSONSample/employee/
  • "employee" (method=POST) with batch request : Insert a set of new employee to the database with the given information. A sample payload saved as the employee-payload.json file, that can be used when sending the data is given below.

    {
        "_postemployee_batch_req": {
            "_postemployee": [
                {
                    "employeeNumber": "5012",
                    "lastName": "Smith",
                    "firstName": "Will",
                    "email": "will@smith.com",
                    "salary": "13500.0"
                },
                {
                    "employeeNumber": "5013",
                    "lastName": "Peter",
                    "firstName": "Parker",
                    "email": "peter@parker.com",
                    "salary": "15500.0"
                }
            ]
        }
    }

    The HTTP request sent using CURL would be as follows:

    curl -X POST -H 'Accept: application/json'  -H 'Content-Type: application/json' --data "@employee-payload.json" http://localhost:9763/services/samples/JSONSample/employee_batch_req
  • "employee" (method=PUT) - Updates an existing user with new information. A sample payload saved as the employee-payload-update.json file, that can be used when sending the data is given below.

    {
      "_putemployee": {
        "employeeNumber" : "14001",
        "lastName": "Smith",
        "firstName": "Will",
        "email": "will@smith.com",
        "salary": "78500.0"
      }
    }


    The HTTP request sent using CURL would be as follows:

    curl -X PUT -H 'Accept: application/json'  -H 'Content-Type: application/json' --data "@employee-payload-update.json" http://localhost:9763/services/samples/JSONSample/employee/
  • "employee" (method=GET) - Retrieve an existing employee.  The HTTP request sent using CURL would be as follows:

    curl -X GET -H 'Accept: application/json'  http://localhost:9763/services/samples/JSONSample/employee/14001

 

  • No labels