CLI HTTP - GradedJestRisk/web-training GitHub Wiki

Table of Contents

General

List:

  • httpie;
  • curl;
  • wget.
Dummy API for tests

httpie

API

General:

  • send (default GET): http perdu.com
  • send VERB: http GET perdu.com
  • print header only: http -h perdu.com
  • send data
    • in query params:http --header GET https://www.google.com/search q==test (for search ?q=test)
    • in form: http -f POST httpbin.org/post hello=World

Curl

GET

Get curl <URL>

curl www.perdu.com
<html><head><title>Vous Etes Perdu ?</title></head><body><h1>Perdu sur l'Internet ?</h1><h2>Pas de panique, on va vous aider</h2></body></html>

Store to file curl <OUTPUT_FILE_PATH> <URL>

curl -o index.html www.perdu.com
head index.html
<html><head><title>Vous Etes Perdu ?</title></head><body><h1>Perdu sur l'Internet ?</h1><h2>Pas de panique, on va vous aider</h2></body></html>

POST

JSON

<coede> curl --header "Content-Type: application/json" -d '{id:1}' http://localhost:3000/recipes &lt;/code&gt;</coede>

Options

List:

  • headers: &#45;H, &#45;&#45;header + &lt;HEADER&gt;
  • output to file &#45;o + &lt;OUTPUT_FILE_PATH&gt;

Sample

You can get them from Mozilla:

  • dev tools
  • network
  • copy / copy as CURL
⚠️ **GitHub.com Fallback** ⚠️