/gin-rest-api

When life gives you HTTP requests, just add some Gin and watch your app shine!

Primary LanguageGoMIT LicenseMIT

CRUD API with Gin

This is a simple CRUD API built using the Go programming language and the Gin web framework. The API allows you to manage tags through basic operations like creating, reading, updating, and deleting.

Installation and Setup

With Docker

Click Me
  1. Clone the repository
  2. Use docker-compose to run the server
git clone git@github.com:geekyharsh05/gin-rest-api.git
cd gin-rest-api
docker-compose up -d

Without Docker

Click Me
  1. Clone the repository
  2. Install the dependencies
  3. Run the server
git clone git@github.com:geekyharsh05/gin-rest-api.git
cd cd gin-rest-api
go mod tidy
go run main.go

NOTE: Setup environment variable in .env from .env.example

You can use PostgresSQL as the database for this project. To set up the database, follow these steps:

docker run --name postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres:alpine

API Endpoints

The following endpoints are available in the application:

  • GET /api/tags: Retrieve all tags.
  • GET /api/tags/:tagId: Retrieve a tag by ID.
  • POST /api/tags: Create a new tag.
  • PATCH /api/tags/:tagId: Update an existing tag by ID.
  • DELETE /api/tags/:tagId: Delete a tag by ID.

Usage

To use the API, you can make HTTP requests to the endpoints. Here's an example of how to create a new tag:

curl --request POST \
  --url http://localhost:8888/api/tags \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Golang"
}

Swagger Documentation

The API also provides a Swagger documentation endpoint. You can access it by making a GET request to the following URL:

http://localhost:8888/docs/index.html

This will display the Swagger documentation page, which includes information about the available endpoints, their parameters, and their responses.

Author

Author Name   :   Harsh Vardhan Pandey
Author URI       :   www.aboutharsh.vercel.app
GitHub URI       :   geekyharsh05

License

License: MIT