Developing a REST service - imona/tutorial GitHub Wiki

For developing a REST service, one needs to choose between two HTTP methods:

  • GET: Choose if the service does not modify any data, and no data is passed to the server in the request.
  • POST: Choose if the service modifies data on the server. Data can be passed to the server in the request.

URL parameters for the service can be added/removed. These parameters are provided as part of the service URL. In order to access their values in the service script, using name of the URL parameter is enough.

Code example:
Assume that a URL parameter named "param_name" is defined for the service. It can be used as follows:

customer.name = param_name;

A response entity can be specified for a service. Once it is specified, the service is expected to return an object of that entity type.

If the service uses POST method, it may define a request entity as well. Callers of the service need to provide a JSON object that correspond to the entity in their requests. This object can be used in the service script as input.

Example:
A service uses an entity named "Customer" as its request entity. The "Customer" entity has a term named "name". Clients of the service may send the following request to save a new Customer:

{
  "name": "Mike"
}

and then use it in the service script as follows:

save(input);  

This saves a new Customer object to the database.