Skip to content

Instantly share code, notes, and snippets.

@gopinath-langote
Last active May 30, 2024 08:27
Show Gist options
  • Save gopinath-langote/17de24551a256243e93545c641ad88f3 to your computer and use it in GitHub Desktop.
Save gopinath-langote/17de24551a256243e93545c641ad88f3 to your computer and use it in GitHub Desktop.
libary-service-apis

Library Service API

Tech Stack

  1. Go Lang
  2. Postgres

API Testing

Ping the server

curl -X GET http://localhost:8080/ping

200 Response

{
  "message": "pong"
}

500 Response

{
  "error": "Internal server error."
}

Get All Books

curl -X GET http://localhost:8080/books

200 Response

{
  "books": [
    {
      "id": "1",
      "title": "To Kill a Mockingbird",
      "price": 10.99,
      "publishedDate": "1960-07-11"
    },
    {
      "id": "2",
      "title": "The Great Gatsby",
      "price": 15.99,
      "publishedDate": "1925-04-10"
    }
  ]
}

Add New Book

curl -X POST http://localhost:8080/books \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "The Great Gatsby",
    "price": 15.99,
    "publishedDate": "1925-04-10"
  }'

200 Response

{
  "id": "101",
  "title": "The Great Gatsby",
  "price": 15.99,
  "publishedDate": "1925-04-10",
  "message": "Book successfully added to the library."
}

Get a book by ID

curl -X GET http://localhost:8080/books/1

200 Response

{
  "id": "1",
  "title": "To Kill a Mockingbird",
  "price": 10.99,
  "publishedDate": "1960-07-11"
}

Update a book title

curl -X PUT http://localhost:8080/books/1 \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "Updated Book Title"
  }'

200 Response

{
  "id": "1",
  "title": "Updated Book Title",
  "message": "Book title successfully updated."
}

Delete a book by ID

curl -X DELETE http://localhost:8080/books/1

200 Response

{
  "id": "1",
  "message": "Book successfully deleted."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment