This is a simple CRUD (Create, Read, Update, Delete) API for managing a collection of movies, built using Go and the Gorilla Mux router. This project demonstrates basic API operations and can be expanded or integrated with a database for more advanced use.
- Get all movies: Retrieve a list of all movies in the collection.
- Get a single movie: Retrieve a specific movie by its ID.
- Create a new movie: Add a new movie to the collection.
- Update a movie: Modify the details of an existing movie.
- Delete a movie: Remove a movie from the collection.
GET /api/movies
: Get all movies.GET /api/movies/{id}
: Get a specific movie by ID.POST /api/movies
: Create a new movie.PUT /api/movies/{id}
: Update an existing movie by ID.DELETE /api/movies/{id}
: Delete a movie by ID.
- Go 1.16 or later installed on your machine.
- Clone the repository:
git clone https://github.com/aydenjahola/go-crud-api.git
cd go-crud-api
To run the API server locally, execute:
go run main.go
This will start the server on http://localhost:8000
. You can use tools like curl
, Postman
, or your web browser to interact with the API.
curl -X GET http://localhost:8000/api/movies
curl -X GET http://localhost:8000/api/movies/1
curl -X POST http://localhost:8000/api/movies -H "Content-Type: application/json" -d '{"isbn":"123456","title":"New Movie","director":{"firstname":"Jane","lastname":"Doe"}}'
curl -X PUT http://localhost:8000/api/movies/1 -H "Content-Type: application/json" -d '{"isbn":"654321","title":"Updated Movie","director":{"firstname":"Jane","lastname":"Doe"}}'
curl -X DELETE http://localhost:8000/api/movies/1
main.go
: The entry point of the application. It sets up the routes and starts the server.Movie
andDirector
structs: Represent the movie and its director.- CRUD operations: Implemented in separate functions for readability and organization.
- Database Integration: Replace the hardcoded data with a persistent database.
- Error Handling: Improve error handling and validation for API inputs.
- Authentication: Implement user authentication for secure API access.