liveBook · Manning

Curl

As explained in Learn Go with Pocket-Sized Projects

curl is a command-line tool for transferring data to and from network services, including HTTP servers.

curl is a command-line tool for sending requests to network services. It is useful for checking a running HTTP server without building a separate client; commands are also easy to repeat and automate. section 8.1.2

Check a local server

Start the Go server with `go run .`, then run `curl http://localhost:8080`. With the initial nil handler, the response is 404. Keep the server running while issuing requests; stop it with Ctrl–C afterward. section 8.1.2

> curl -v localhost:8080/games
    Output:
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /games HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> < HTTP/1.1 405 Method Not Allowed
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

Run `curl -v localhost:8080/games` to see both sides of the exchange. curl sends GET when no method is specified; this endpoint rejects it with `405 Method Not Allowed`. section 8.2.1

Send the intended method

Run `curl -v -X POST localhost:8080/games`. The verbose output shows a POST request and, in the initial handler, a `200 OK` response with `Creating a new game`. The handler is later changed to send `201 Created`, writing the status before the response body. section 8.2.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Demonstrates commands, method selection, and verbose response inspection, but does not develop curl scripting or configuration.
Examples
Shows requests to localhost:8080 and /games, including a 404, a verbose 405 response, and a POST response.
What it assumes
Assumes a running local Go HTTP server while introducing curl commands and the default GET request through examples.
What you can do after
Apply it via curl to probe a local HTTP endpoint, choose POST, and inspect the returned status and body.
How it connects
Connects HTTP requests, GET and POST methods, handlers, and status codes through endpoint checks.

Also explained in

Compare how 2 books explain curl →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.