A simple, lightweight RESTful API for performing CRUD (Create, Read, Update, Delete) operations on a movie collection. This project is built in Go and uses the gorilla/mux router for handling HTTP requests.
The application runs a local web server and manages a list of movies in-memory.
- Full CRUD Operations: Implements all four essential CRUD operations (Create, Read, Update, Delete) for managing movie records.
- RESTful API Design: Follows REST principles for a clean and predictable API structure.
- JSON Data Handling: Uses JSON as the data format for both request bodies and API responses, ensuring wide compatibility.
- Efficient Routing: Leverages the popular
gorilla/muxrouter to handle HTTP requests and URL parameters efficiently. - Lightweight & Standalone: Runs as a single Go application with no external database dependencies, using an in-memory slice for data storage.
Follow these instructions to get the project running on your local machine.
-
Clone the repository (or save the code as
main.goin a new directory). -
Navigate to the project directory and install the required dependency:
go mod tidy
-
Run the server:
go run main.go
The server will start on
http://localhost:8000.
The base URL for all endpoints is http://localhost:8000.
| Action | Method | Endpoint | Description |
|---|---|---|---|
| Get All Movies | GET |
/movies |
Retrieves a list of all movies in the collection. |
| Get Single Movie | GET |
/movies/{id} |
Retrieves a single movie by its unique ID. |
| Create Movie | POST |
/movies |
Adds a new movie to the collection. The ID is auto-generated. |
| Update Movie | PUT |
/movies/{id} |
Updates the details of an existing movie by its ID. |
| Delete Movie | DELETE |
/movies/{id} |
Removes a movie from the collection by its ID. |
curl -X GET http://localhost:8000/moviescurl -X GET http://localhost:8000/movies/1curl -X POST -H "Content-Type: application/json" -d '{
"isbn": "987654",
"title": "Movie Three",
"director": {
"firstname": "Jane",
"lastename": "Roe"
}
}' http://localhost:8000/moviescurl -X PUT -H "Content-Type: application/json" -d '{
"isbn": "45455-2",
"title": "Movie Two (Updated)",
"director": {
"firstname": "Steven",
"lastename": "Smith"
}
}' http://localhost:8000/movies/2curl -X DELETE http://localhost:8000/movies/1Thank you for exploring this project