Skip to content

Latest commit

 

History

History

api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

API package documentation

The api package implements the API layer of the application, providing a structured approach to manage HTTP servers, routes, handlers, and request/response mappings.

Components

Server

The Server struct manages the lifecycle of the HTTP server. It is responsible for:

  • Listening for incoming requests.
  • Serving responses via the http.Server.
  • Gracefully shutting down the server when required.

This component is highly configurable, allowing you to set:

  • Server address and port.
  • Read and write timeouts.

Router

The default router is based on the lightweight Chi router, which can be replaced with any router implementing the http.Handler interface.

Features:

Handler

The Handler struct serves as a generic interface for handling incoming HTTP requests. It decouples business logic from the HTTP layer by:

  • Validating and passing the request's context and inputs to the service functions.
  • Returning a response or error from the service functions.

How to Use:

Mappers

The Mappers struct simplifies the process of translating HTTP requests into service-layer inputs and mapping service outputs to HTTP responses.

Key Features:

  • No need to create new handlers for each endpoint.
  • Implement the following interfaces for custom mappings:

Examples:
The mappers package includes examples for handling various types of requests and responses.