Building a Metro Rail API with go-restful
Let us use the knowledge we gained in the previous section and create an API for the City Metro Rail project we talked about in the preceding section. The roadmap is as follows:
- Design a REST API document.
- Create models for a database.
- Implement the API logic.
Design specification
Before creating any API, we should know what the specifications of APIs are in the form of a document. We showed a few examples in the previous chapters, including the URL shortener API design document. Let us try to create one for this Metro Rail project. Take a look at the following table:
HTTP verb | Path | Action | Resource |
|
| Create | Train |
|
| Create | Station |
|
| Read | Train |
|
| Read | Station |
|
| Create | Route |
We can also include the UPDATE
and DELETE
methods. By implementing the preceding design, it will be obvious for users to implement them on their own.