github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/v2/library/go-api.md (about)

     1  ---
     2  title: Go API
     3  keywords: go-api
     4  tags: [go-micro]
     5  sidebar: home_sidebar
     6  permalink: /go-api
     7  summary: a package for defining api routes and handlers
     8  ---
     9  
    10  # Overview
    11  
    12  Go API is a pluggable API framework driven by service discovery to help build powerful public API gateways.
    13  
    14  The Go API library provides api gateway routing capabilities. A microservice architecture decouples application logic into 
    15  separate service. An api gateway provides a single entry point to consolidate these services into a unified api. The 
    16  Go API uses routes defined in service discovery metadata to generate routing rules and serve http requests.
    17  
    18  <img src="https://micro.dev/docs/images/go-api.png?v=1" alt="Go API" />
    19  
    20  Go API is the basis for the [micro api](https://micro.dev/docs/api.html).
    21  
    22  ## Handlers
    23  
    24  Handlers are http handlers used for handling requests. It uses the `http.Handler` pattern for convenience.
    25  
    26  - [`api`](#api-handler) - Handles any HTTP request. Gives full control over the http request/response via RPC.
    27  - [`broker`](#broker-handler) - A http handler which implements the go-micro broker interface
    28  - [`cloudevents`](#cloudevents-handler) -  Handles CloudEvents and publishes to a message bus.
    29  - [`event`](#event-handler) -  Handles any HTTP request and publishes to a message bus.
    30  - [`http`](#http-handler) - Handles any HTTP request and forwards as a reverse proxy.
    31  - [`registry`](#registry-handler) - A http handler which implements the go-micro registry interface
    32  - [`rpc`](#rpc-handler) - Handles json and protobuf POST requests. Forwards as RPC.
    33  - [`web`](#web-handler) - The HTTP handler with web socket support included.
    34  
    35  ## API Handler
    36  
    37  The API handler is the default handler. It serves any HTTP requests and forwards on as an RPC request with a specific format.
    38  
    39  - Content-Type: Any
    40  - Body: Any
    41  - Forward Format: [api.Request](https://github.com/micro/go-micro/blob/master/api/proto/api.proto#L11)/[api.Response](https://github.com/micro/go-micro/blob/master/api/proto/api.proto#L21)
    42  - Path: `/[service]/[method]`
    43  - Resolver: Path is used to resolve service and method
    44  
    45  ## Broker Handler
    46  
    47  The broker handler is a http handler which serves the go-micro broker interface
    48  
    49  - Content-Type: Any
    50  - Body: Any
    51  - Forward Format: HTTP
    52  - Path: `/`
    53  - Resolver: Topic is specified as a query param
    54  
    55  Post the request and it will be published
    56  
    57  ## CloudEvents Handler
    58  
    59  The CloudEvents handler serves HTTP and forwards the request as a CloudEvents message over a message bus using the go-micro/client.Publish method.
    60  
    61  - Content-Type: Any
    62  - Body: Any
    63  - Forward Format: Request is formatted as [CloudEvents](https://github.com/cloudevents/spec) message
    64  - Path: `/[topic]`
    65  - Resolver: Path is used to resolve topic
    66  
    67  ## Event Handler
    68  
    69  The event handler serves HTTP and forwards the request as a message over a message bus using the go-micro/client.Publish method.
    70  
    71  - Content-Type: Any
    72  - Body: Any
    73  - Forward Format: Request is formatted as [go-api/proto.Event](https://github.com/micro/go-api/blob/master/proto/api.proto#L28L39) 
    74  - Path: `/[topic]/[event]`
    75  - Resolver: Path is used to resolve topic and event name
    76  
    77  ## HTTP Handler
    78  
    79  The http handler is a http reverse proxy with built in service discovery.
    80  
    81  - Content-Type: Any
    82  - Body: Any
    83  - Forward Format: HTTP Reverse proxy
    84  - Path: `/[service]`
    85  - Resolver: Path is used to resolve service name
    86  
    87  ## Registry Handler
    88  
    89  The registry handler is a http handler which serves the go-micro registry interface
    90  
    91  - Content-Type: Any
    92  - Body: JSON
    93  - Forward Format: HTTP
    94  - Path: `/`
    95  - Resolver: GET, POST, DELETE used to get service, register or deregister
    96  
    97  ## RPC Handler
    98  
    99  The RPC handler serves json or protobuf HTTP POST requests and forwards as an RPC request.
   100  
   101  - Content-Type: `application/json` or `application/protobuf`
   102  - Body: JSON or Protobuf
   103  - Forward Format: json-rpc or proto-rpc based on content
   104  - Path: `/[service]/[method]`
   105  - Resolver: Path is used to resolve service and method
   106  
   107  ## Web Handler
   108  
   109  The web handler is a http reverse proxy with built in service discovery and web socket support.
   110  
   111  - Content-Type: Any
   112  - Body: Any
   113  - Forward Format: HTTP Reverse proxy including web sockets
   114  - Path: `/[service]`
   115  - Resolver: Path is used to resolve service name
   116  
   117