Giter Site home page Giter Site logo

restful-api-'s Introduction

Todo API

This is a simple RESTful API for managing a todo list, built with Go and the Gin web framework.

Table of Contents

Prerequisites

  • Go 1.18 or higher
  • Docker (optional, for containerization)

Installation

  1. Clone the repository:
git clone https://github.com/Ashikurrahaman287/RESTful-API-.git
cd todo-api
  1. Initialize the Go module and download dependencies:
go mod tidy
  1. Install Gin framework:
go get github.com/gin-gonic/gin

Usage

  1. Run the application:
go run main.go
  1. The API will be available at http://localhost:8080.

API Endpoints

Create a new todo

  • URL: /todos
  • Method: POST
  • Body:
{
"title": "New Todo"
}
  • Success Response:
  • Code: 201 CREATED
  • Content:
{
"id": 1,
"title": "New Todo",
"completed": false
}

Get all todos

  • URL: /todos
  • Method: GET
  • Success Response:
  • Code: 200 OK
  • Content:
[
{
"id": 1,
"title": "New Todo",
"completed": false
}
]

Get a todo by ID

  • URL: /todos/:id
  • Method: GET
  • Success Response:
  • Code: 200 OK
  • Content:
{
"id": 1,
"title": "New Todo",
"completed": false
}
  • Error Response:
  • Code: 404 NOT FOUND
  • Content:
{
"error": "Todo not found"
}

Update a todo

  • URL: /todos/:id
  • Method: PUT
  • Body:
{
"title": "Updated Todo",
"completed": true
}
  • Success Response:
  • Code: 200 OK
  • Content:
{
"id": 1,
"title": "Updated Todo",
"completed": true
}
  • Error Response:
  • Code: 404 NOT FOUND
  • Content:
{
"error": "Todo not found"
}

Delete a todo

  • URL: /todos/:id
  • Method: DELETE
  • Success Response:
  • Code: 204 NO CONTENT
  • Error Response:
  • Code: 404 NOT FOUND
  • Content:
{
"error": "Todo not found"
}

Docker

You can also run the application using Docker.

  1. Build the Docker image:
docker build -t todo-api .
  1. Run the Docker container:
docker run -p 8080:8080 todo-api

Contributing

If you want to contribute to this project, feel free to submit issues or pull requests. [email protected]

License

This project is licensed under the MIT License.

restful-api-'s People

Contributors

ashikurrahaman287 avatar

Stargazers

SpudBlocks avatar  avatar

Watchers

 avatar

Forkers

spudblocks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.