File: README.md

package info (click to toggle)
golang-github-valyala-fasthttp 1%3A1.59.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: makefile: 34
file content (21 lines) | stat: -rw-r--r-- 939 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Client Example

The Client is useful when working with multiple hostnames.

See the simplest `sendGetRequest()` for GET and more advanced `sendPostRequest()` for a POST request.

The `sendPostRequest()` also shows:
* Per-request timeout with `DoTimeout()`
* Send a body as bytes slice with `SetBodyRaw()`. This is useful if you generated a request body. Otherwise, prefer `SetBody()` which copies it.
* Parse JSON from response
* Gracefully show error messages i.e. timeouts as warnings and other errors as a failures with detailed error messages.

## How to build and run
Start a web server on localhost:8080 then execute:

    make
    ./client

## Client vs HostClient
Internally the Client creates a dedicated HostClient for each domain/IP address and cleans unused after period of time.
So if you have a single heavily loaded API endpoint it's better to use HostClient. See an example in the [examples/host_client](../host_client/)