In the previous chapters, we explored all the possible ways of building a RESTful API. We used basic HTTP routers, as well as many other web frameworks. However, to keep it simple, we can use gorilla/mux with mongo-driver for the MongoDB driver. In this section, we will build an end-to-end movie API while integrating the database and HTTP router. In the previous section, we learned how to create a new MongoDB document and retrieve it using mongo-driver. By consolidating our knowledge of HTTP routers and databases, we can create a movie API.
Let's create the plan so that we can create the API:
- Prepare structs to hold movie information and the database connection.
- Create a server for hosting the API.
- Prepare the routes for the API endpoints.
- Implement handlers for the routes.
We have to follow these steps to achieve our goal:
- Create...