Skip to content

chethanm99/Go-CRUD-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go Movie CRUD API

A simple, lightweight RESTful API for performing CRUD (Create, Read, Update, Delete) operations on a movie collection. This project is built in Go and uses the gorilla/mux router for handling HTTP requests.

The application runs a local web server and manages a list of movies in-memory.

Features

  • Full CRUD Operations: Implements all four essential CRUD operations (Create, Read, Update, Delete) for managing movie records.
  • RESTful API Design: Follows REST principles for a clean and predictable API structure.
  • JSON Data Handling: Uses JSON as the data format for both request bodies and API responses, ensuring wide compatibility.
  • Efficient Routing: Leverages the popular gorilla/mux router to handle HTTP requests and URL parameters efficiently.
  • Lightweight & Standalone: Runs as a single Go application with no external database dependencies, using an in-memory slice for data storage.

Getting Started

Follow these instructions to get the project running on your local machine.

Prerequisites

  • Go (version 1.18 or newer)
  • An API client like curl or Postman

Installation & Usage

  1. Clone the repository (or save the code as main.go in a new directory).

  2. Navigate to the project directory and install the required dependency:

    go mod tidy
  3. Run the server:

    go run main.go

    The server will start on http://localhost:8000.

API Endpoints

The base URL for all endpoints is http://localhost:8000.

Action Method Endpoint Description
Get All Movies GET /movies Retrieves a list of all movies in the collection.
Get Single Movie GET /movies/{id} Retrieves a single movie by its unique ID.
Create Movie POST /movies Adds a new movie to the collection. The ID is auto-generated.
Update Movie PUT /movies/{id} Updates the details of an existing movie by its ID.
Delete Movie DELETE /movies/{id} Removes a movie from the collection by its ID.

Request Examples

Get All Movies

curl -X GET http://localhost:8000/movies

Get a Movie by ID

curl -X GET http://localhost:8000/movies/1

Create a New Movie

curl -X POST -H "Content-Type: application/json" -d '{
    "isbn": "987654",
    "title": "Movie Three",
    "director": {
        "firstname": "Jane",
        "lastename": "Roe"
    }
}' http://localhost:8000/movies

Update a Movie by ID

curl -X PUT -H "Content-Type: application/json" -d '{
    "isbn": "45455-2",
    "title": "Movie Two (Updated)",
    "director": {
        "firstname": "Steven",
        "lastename": "Smith"
    }
}' http://localhost:8000/movies/2

Delete a Movie by ID

curl -X DELETE http://localhost:8000/movies/1

Thank you for exploring this project

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages