We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

HTTP Post

You probably already figured this out (or knew), but curl is a command line tool for making HTTP requests. If you cat the /tmp/rawget.http file that we created, you should have something very similar to this:

GET /goodies HTTP/1.1
Host: localhost:42069
User-Agent: curl/8.6.0
Accept: */*

This is what a raw HTTP message looks like - specifically a raw HTTP GET request.

  • Request line: GET /goodies HTTP/1.1
  • Headers: Host: localhost:42069, User-Agent: curl/8.6.0, Accept: */*
  • Body: (empty)

Let's see what a raw HTTP POST request (with a body) looks like...

Assignment

  1. go run ./cmd/tcplistener | tee /tmp/rawpost.http
    
  2. curl -X POST -H "Content-Type: application/json" -d '{"flavor":"dark mode"}' http://localhost:42069/coffee
    

    Again, this time your cURL command will hang, but this time, you might notice that the body ({"flavor":"dark mode"}) isn't showing up yet in the tcplistener output... and that's because it doesn't end with a newline.

Run and submit the CLI tests.