Coder Social home page Coder Social logo

go-api's Introduction

👽Go API

This project is a simple book inventory management API implemented in Go using the Gin web framework. It provides basic functionalities such as retrieving a list of books, retrieving a specific book by ID, creating a new book entry, checking out a book (decreasing its quantity), and returning a book (increasing its quantity). The data is stored in memory as a static list of books.

Project Structure

  • main.go: Contains the main application logic, including the setup of the Gin router and the implementation of CRUD operations for the book inventory.

API Endpoints

  1. GET /books: Retrieve a list of all books.

  2. GET /books/:id: Retrieve details of a specific book by ID.

  3. POST /books: Create a new book entry.

  4. PATCH /checkout: Check out a book by decreasing its quantity (Query parameter style).

  5. PATCH /return: Return a book by increasing its quantity (Query parameter style).

Book Structure

  • Each book has an ID, Title, Author, and Quantity.

    type Book struct {
      ID       string `json:"id"`
      Title    string `json:"title"`
      Author   string `json:"author"`
      Quantity int    `json:"quantity"`
    }

How to Run

  1. Ensure you have Go installed on your machine.
  2. Run the following command to install the required dependencies:
go get -u github.com/gin-gonic/gin

Execute the main.go file to start the server:

go run main.go

• Access the API at http://localhost:8080.

API Usage

Use tools like curl or Postman to interact with the API endpoints. Example: To check out a book, send a PATCH request to http://localhost:8080/checkout?id=<book_id>.

Note

This is a simple demonstration project, and it uses in-memory data storage. For a production scenario, consider using a database for persistent data storage.

Author

© 2024 - Boularbah Ismail; Twitter.

go-api's People

Contributors

boularbahsmail avatar

Stargazers

 avatar

Watchers

 avatar

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.