A simple REST API built with Go for managing a movie collection. This API provides CRUD (Create, Read, Update, Delete) operations for movies with basic director information.
- Get all movies
- Get a specific movie by ID
- Create a new movie
- Update an existing movie
- Delete a movie
- In-memory storage (data persists only during runtime)
Watch a screen recording demonstration of the API in action:
go-movies.-.abhinavs.Workspace.2025-06-02.02-31-48.1.1.mp4
{
"id": "string",
"isbn": "string",
"title": "string",
"director": {
"firstname": "string",
"lastname": "string"
}
}
- Go 1.16 or higher
- Gorilla Mux router
- Clone the repository
- Install dependencies:
go mod init movies-api go get github.com/gorilla/mux
- Run the application:
go run main.go
The server will start on port 8001.
Returns all movies in the collection.
Response:
[
{
"id": "1",
"isbn": "438277",
"title": "Movie one",
"director": {
"firstname": "Cristiano",
"lastname": "Ronaldo"
}
}
]
Returns a specific movie by ID.
Parameters:
id
(path parameter) - Movie ID
Response:
{
"id": "1",
"isbn": "438277",
"title": "Movie one",
"director": {
"firstname": "Cristiano",
"lastname": "Ronaldo"
}
}
Creates a new movie. The ID is automatically generated.
Request Body:
{
"isbn": "123456",
"title": "New Movie",
"director": {
"firstname": "John",
"lastname": "Doe"
}
}
Response:
{
"id": "87654321",
"isbn": "123456",
"title": "New Movie",
"director": {
"firstname": "John",
"lastname": "Doe"
}
}
Updates an existing movie by ID.
Parameters:
id
(path parameter) - Movie ID
Request Body:
{
"isbn": "654321",
"title": "Updated Movie",
"director": {
"firstname": "Jane",
"lastname": "Smith"
}
}
Deletes a movie by ID and returns the updated movie list.
Parameters:
id
(path parameter) - Movie ID
Response: Returns the remaining movies after deletion.
The API comes pre-loaded with two sample movies:
- Movie One (ID: 1) - Directed by Cristiano Ronaldo
- Movie Two (ID: 2) - Directed by David Goggins
You can test the API using tools like:
- Postman
- curl
- Any HTTP client
# Get all movies
curl http://localhost:8001/movies
# Get specific movie
curl http://localhost:8001/movies/1
# Create new movie
curl -X POST http://localhost:8001/movies \
-H "Content-Type: application/json" \
-d '{"isbn":"123456","title":"Test Movie","director":{"firstname":"Test","lastname":"Director"}}'
# Update movie
curl -X PUT http://localhost:8001/movies/1 \
-H "Content-Type: application/json" \
-d '{"isbn":"updated","title":"Updated Movie","director":{"firstname":"Updated","lastname":"Director"}}'
# Delete movie
curl -X DELETE http://localhost:8001/movies/1
├── LICENSE
├── README.md
├── go.mod
├── go.sum
├── main.go
└── crudapi.exe (compiled binary)
Add database persistence (PostgreSQL/MongoDB) Implement input validation Add authentication and authorization Include unit tests Add logging middleware Implement pagination for movie lists Add search functionality
Fork the repository Create a feature branch (git checkout -b feature/new-feature) Commit your changes (git commit -am 'Add new feature') Push to the branch (git push origin feature/new-feature) Create a Pull Request
This is a simple in-memory implementation - data will be lost when the server restarts Movie IDs are generated randomly using rand.Intn(100000000) The API uses JSON for all request/response bodies No authentication or validation is implemented The crudapi.exe is the compiled Windows executable
This project is licensed under the MIT License - see the LICENSE file for details.
-
Gorilla Mux - HTTP router and URL matcher
GitHub : abhinav-phi
Project Link : click here
⭐ If you found this project helpful, please give it a star!