This is a simple CRUD (Create, Read, Update, Delete) API for managing movies using Golang. It doesn't use a database, but rather manipulates data stored in memory using Go structs and slices.
- GET /movies: Retrieve all movies.
- GET /movies/{id}: Retrieve a specific movie by ID.
- POST /movies: Create a new movie.
- PUT /movies/{id}: Update a specific movie by ID.
- DELETE /movies/{id}: Delete a specific movie by ID.
- Go 1.16+
- Gorilla Mux
To install the necessary dependencies, run:
go get -u github.com/gorilla/mux
- Clone the repository or copy the code into a Go project.
- Run the application:
go run main.go
- The server will start on port
8000
. Access the API athttp://localhost:8000
.
Method | Endpoint | Description |
---|---|---|
GET | /movies |
Get all movies |
GET | /movies/{id} |
Get a movie by ID |
POST | /movies |
Create a new movie |
PUT | /movies/{id} |
Update a movie by ID |
DELETE | /movies/{id} |
Delete a movie by ID |
- Create a Movie (POST)
curl -X POST http://localhost:8000/movies \
-H "Content-Type: application/json" \
-d '{"Isbn": "12345", "Title": "New Movie", "Director": {"Firstname": "John", "Lastname": "Doe"}}'
- Get All Movies (GET)
curl -X GET http://localhost:8000/movies
This API uses in-memory data storage, meaning all data will be lost once the server is stopped.