Designing REST Web services
Identifying the resources to expose to a RESTful Web service client is an essential step in designing a RESTful Web service server.
Each component in a RESTful web service is a resource that can be accessed using standard HTTP methods. To identify the resources, analyze your business domain and extract the nouns (and most appropriately pluralized nouns) that are relevant to your business needs. For example, "customers" and "accounts" are resources in a typical business domain.
Once the nouns (resources) have been identified, then the interactions with REST web services can be modeled as HTTP verbs against these nouns. REST relies on this resource/HTTP method combination.
- quotes
- /id
- /price
- /category
- etc.
- companies
- /id
- /name
- /rating
- etc.
- users
- /id
- /name
- etc.
Define resource endpoints
You may find it helpful also to think of the resource in terms of CRUD, where each resource supports the action of Create, Read, Update, and Delete using the HTTP verbs PUT, GET, POST, DELETE.
Users
GET http://localhost:8090/StockQuote/users - Return a list of all users (requires authentication)
GET http://localhost:8090/StockQuote/users/id - Return the user with that id
POST http://localhost:8090/StockQuote/users - Create a new user. Return a 201 status code and the newly created id
PUT http://localhost:8090/StockQuote/users/id - Update the user with that id
DELETE http://localhost:8090/StockQuote/users/id - Delete the user with that id
Functions in the REST web service now need to be created to respond to requests for services based on those endpoints.
It is recommended to always use the GWS REST high-level framework in your Web service. Functions require considerably less code in your application and are easier to use in comparison with low-level APIs.