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.