2025-12-05 19:14:01 -03:00
2025-12-05 19:14:01 -03:00
2025-12-05 19:14:01 -03:00
2025-12-05 19:14:01 -03:00
2025-12-05 19:14:01 -03:00

Go Book API Example

This is a simple Go web service that provides a basic API for retrieving book information. It's built using the chi router and serves hardcoded book data from memory.

Project Structure

  • main.go: Application entry point, sets up the HTTP server and defines the /books/{id} endpoint.
  • internal/handlers/book_handler.go: Contains the BookHandler responsible for processing requests to the /books/{id} endpoint. It uses an in-memory list of books.
  • internal/models/book.go: Defines the Book struct used to represent book data.

Getting Started

Prerequisites

  • Go (version 1.16 or higher recommended)

Running the Application

  1. Clone the repository:

    git clone <repository_url>
    cd testing-go-example
    

    (Note: Replace <repository_url> with the actual repository URL if this project were hosted.)

  2. Run the server:

    go run main.go
    

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

API Endpoints

GET /books/{id}

Retrieves details for a single book by its ID.

Example Request:

curl http://localhost:3000/books/1

Example Response:

{
  "id": "1",
  "title": "The Hitchhiker's Guide to the Galaxy",
  "author": "Douglas Adams"
}
curl http://localhost:3000/books/2

Example Response:

{
  "id": "2",
  "title": "The Restaurant at the End of the Universe",
  "author": "Douglas Adams"
}
Description
No description provided
Readme 27 KiB
Languages
Go 100%