This is a simple CRUD (Create, Read, Update, Delete) API for managing movies, implemented in Go.
- Clone the repository:
git clone https://github.com/Darshan016/CRUD-APIs-in-Go.git
- Change to the project directory:
cd <your_directory_name>
- Install dependencies:
go mod tidy
- Run the application:
go run main.go
After running the application, the API will be available at http://localhost:8080
.
- URL:
/movies
- Method:
POST
- Request Body:
{ "isbn": "string", "title": "string", "director": { "name": "string" } }
- Success Response:
- Code: 201 CREATED
- Content:
{ "id": "string", "isbn": "string", "title": "string", "director": { "name": "string" } }
- URL:
/movies
- Method:
GET
- Success Response:
- Code: 200 OK
- Content:
[ { "id": "string", "isbn": "string", "title": "string", "director": { "name": "string" } }, ... ]
- URL:
/movies/{id}
- Method:
GET
- URL Params:
- id:
string
- id:
- Success Response:
- Code: 200 OK
- Content:
{ "id": "string", "isbn": "string", "title": "string", "director": { "name": "string" } }
- Error Response:
- Code: 404 NOT FOUND
- Content:
Movie not found
- URL:
/movies/{id}
- Method:
PUT
- URL Params:
- id:
string
- id:
- Request Body:
{ "isbn": "string", "title": "string", "director": { "name": "string" } }
- Success Response:
- Code: 200 OK
- Content:
{ "id": "string", "isbn": "string", "title": "string", "director": { "name": "string" } }
- Error Response:
- Code: 404 NOT FOUND
- Content:
Movie not found
- URL:
/movies/{id}
- Method:
DELETE
- URL Params:
- id:
string
- id:
- Success Response:
- Code: 204 NO CONTENT
- Error Response:
- Code: 404 NOT FOUND
- Content:
Movie not found
type Movie struct {
ID string `json:"id"`
Isbn string `json:"isbn"`
Title string `json:"title"`
Director *Director `json:"director"`
}
type Director struct {
Name string `json:"name"`
}