Skip to content

A beginner-friendly Movies CRUD API built using Go and Gorilla Mux. This RESTful service supports basic Create, Read, Update, and Delete operations on an in-memory movie collection. Ideal for learning Go's net/http package, routing, and working with JSON. No external database data resets on every server restart.

License

Notifications You must be signed in to change notification settings

abhinav-phi/Movies-CRUD-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Movies-CRUD-API

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.

Features

  • 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)

Overview - Flowchart

Demo Video

Watch a screen recording demonstration of the API in action:

go-movies.-.abhinavs.Workspace.2025-06-02.02-31-48.1.1.mp4

Data Structure

Movie

{
  "id": "string",
  "isbn": "string", 
  "title": "string",
  "director": {
    "firstname": "string",
    "lastname": "string"
  }
}

Prerequisites

  • Go 1.16 or higher
  • Gorilla Mux router

Installation

  1. Clone the repository
  2. Install dependencies:
    go mod init movies-api
    go get github.com/gorilla/mux
  3. Run the application:
    go run main.go

The server will start on port 8001.

API Endpoints

GET /movies

Returns all movies in the collection.

Response:

[
  {
    "id": "1",
    "isbn": "438277",
    "title": "Movie one",
    "director": {
      "firstname": "Cristiano",
      "lastname": "Ronaldo"
    }
  }
]

GET /movies/{id}

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"
  }
}

POST /movies

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"
  }
}

PUT /movies/{id}

Updates an existing movie by ID.

Parameters:

  • id (path parameter) - Movie ID

Request Body:

{
  "isbn": "654321",
  "title": "Updated Movie",
  "director": {
    "firstname": "Jane",
    "lastname": "Smith"
  }
}

DELETE /movies/{id}

Deletes a movie by ID and returns the updated movie list.

Parameters:

  • id (path parameter) - Movie ID

Response: Returns the remaining movies after deletion.

Sample Data

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

Testing

You can test the API using tools like:

  • Postman
  • curl
  • Any HTTP client

Example curl commands:

# 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

Project Structure

├── LICENSE
├── README.md
├── go.mod
├── go.sum
├── main.go
└── crudapi.exe (compiled binary)

Future Enhancements

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

Contributing

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

Notes

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

  • Gorilla Mux - HTTP router and URL matcher

    📧 Contact

GitHub : abhinav-phi

Project Link : click here


⭐ If you found this project helpful, please give it a star!

About

A beginner-friendly Movies CRUD API built using Go and Gorilla Mux. This RESTful service supports basic Create, Read, Update, and Delete operations on an in-memory movie collection. Ideal for learning Go's net/http package, routing, and working with JSON. No external database data resets on every server restart.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages