• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jeffotoni / quick / 221

06 Mar 2025 07:12PM UTC coverage: 49.324% (-1.2%) from 50.54%
221

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/example/http'

0 of 89 new or added lines in 3 files covered. (0.0%)

1825 of 3700 relevant lines covered (49.32%)

2697.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/example/quick.http.client/quick.get/main.go
1
package main
2

3
import (
4
        "context"
5
        "log"
6
        "time"
7

8
        "github.com/jeffotoni/quick"
9
        "github.com/jeffotoni/quick/http/client"
10
)
11

12
// Example HTTP request using Quick and an external API (reqres.in).
13
// This server listens on port 3000 and forwards GET requests to an external API.
14
// - WithTimeout: Sets the HTTP client timeout to 10 seconds.
15
// - WithContext: Attaches a background context to the client which is not cancellable.
16
// - WithHeaders: Adds custom headers for content type and authorization.
17
// - WithMaxConnsPerHost: Sets the maximum connections allowed per host (20).
18
// - WithDisableKeepAlives: Enables or disables HTTP keep-alives (false = keep-alives enabled).
19

NEW
20
func main() {
×
NEW
21
        q := quick.New()
×
NEW
22

×
NEW
23
        // Define a GET endpoint that forwards requests to an external API.
×
NEW
24
        q.Get("/api/users", func(c *quick.Ctx) error {
×
NEW
25
                // Create an HTTP client with specific configurations.
×
NEW
26
                cClient := client.New(
×
NEW
27
                        // Set the timeout for the HTTP client to 10 seconds.
×
NEW
28
                        client.WithTimeout(10*time.Second),
×
NEW
29
                        client.WithMaxConnsPerHost(20),
×
NEW
30
                        client.WithDisableKeepAlives(false),
×
NEW
31
                        // Add custom headers, including content type and authorization token.
×
NEW
32
                        client.WithHeaders(map[string]string{
×
NEW
33
                                "Content-Type":  "application/json",
×
NEW
34
                                "Authorization": "Bearer EXAMPLE_TOKEN",
×
NEW
35
                        }),
×
NEW
36
                        // Use a background context for the HTTP client. This context cannot be cancelled
×
NEW
37
                        // and does not carry any deadline. It is suitable for operations that run
×
NEW
38
                        // indefinitely or until the application is shut down.
×
NEW
39
                        client.WithContext(context.Background()),
×
NEW
40
                )
×
NEW
41

×
NEW
42
                // Perform a GET request to the external API.
×
NEW
43
                resp, err := cClient.Get("https://reqres.in/api/users/2")
×
NEW
44
                if err != nil {
×
NEW
45
                        // Log the error and return a server error response if the GET request fails.
×
NEW
46
                        log.Println("GET Error:", err)
×
NEW
47
                        return c.Status(500).SendString("Failed to connect to external API")
×
NEW
48
                }
×
49

50
                // Log and return the response body from the external API.
NEW
51
                log.Println("GET Response:", string(resp.Body))
×
NEW
52
                return c.Status(resp.StatusCode).Send(resp.Body)
×
53
        })
54

55
        // Start listening on port 3000 for incoming HTTP requests.
NEW
56
        q.Listen(":3000")
×
57
}
58

59
// curl --location 'http://localhost:3000/api/users' \
60
// --header 'Authorization: Bearer EXAMPLE_TOKEN'
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc