Skip to content

Instantly share code, notes, and snippets.

@Jonamaita
Forked from subfuzion/curl.md
Last active March 8, 2022 18:13
Show Gist options
  • Select an option

  • Save Jonamaita/7df26c36b8df8d5a50b46207ab4b5bc1 to your computer and use it in GitHub Desktop.

Select an option

Save Jonamaita/7df26c36b8df8d5a50b46207ab4b5bc1 to your computer and use it in GitHub Desktop.

Revisions

  1. Jonamaita revised this gist Mar 8, 2022. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion curl.md
    Original file line number Diff line number Diff line change
    @@ -107,10 +107,16 @@ with a data file

    curl -d "@data.json" -X POST http://localhost:3000/data
    ### Post con `login`:
    ### Post with `login`:
    curl -X "POST" 'localhost:8000/get/my/token/' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username":"myuser", "password":"mypass"}'

    ### Post wiht auth basic
    curl -X "POST" -u <user>:<password> 'https://my.url.com' -H 'accept: application/json' -H 'Content-Type: application/json' -d "@data.json"

    ### Change level of ciphers
    curl -X "POST" --ciphers ALL:@SECLEVEL=1 -u <user>:<password> 'https://my.url.com' -H 'accept: application/json' -H 'Content-Type: application/json' -d "@data.json"
    ## GET Examples

    ### Get con token
  2. Jonamaita revised this gist Dec 2, 2021. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -106,7 +106,10 @@ with a data file
    with a data file

    curl -d "@data.json" -X POST http://localhost:3000/data

    ### Post con `login`:
    curl -X "POST" 'localhost:8000/get/my/token/' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username":"myuser", "password":"mypass"}'

    ## GET Examples

    @@ -119,11 +122,7 @@ Tambien es poible que sea `JWT`:
    curl -X "GET" <url_protected> -H 'Authorization: JWT <token>'


    ### Get con `login`:
    curl -X "POST" 'localhost:8000/get/my/token/' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username":"myuser", "password":"mypass"}'

    ## Others

    To get a pretty ouput when use `curl`, we can use or pipe the `json_pp` to pretty print the JSON output.
  3. Jonamaita revised this gist Nov 4, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -108,7 +108,7 @@ with a data file
    curl -d "@data.json" -X POST http://localhost:3000/data


    ## GET
    ## GET Examples

    ### Get con token
    @@ -119,7 +119,7 @@ Tambien es poible que sea `JWT`:
    curl -X "GET" <url_protected> -H 'Authorization: JWT <token>'


    ## Get con `login`:
    ### Get con `login`:
    curl -X "POST" 'localhost:8000/get/my/token/' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username":"myuser", "password":"mypass"}'

  4. Jonamaita renamed this gist Nov 4, 2021. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions curl_post.md → curl.md
    Original file line number Diff line number Diff line change
    @@ -108,6 +108,22 @@ with a data file
    curl -d "@data.json" -X POST http://localhost:3000/data


    ## GET

    ### Get con token
    curl -X "GET" <url_protected> -H 'Authorization: Bearer <token>'
    Tambien es poible que sea `JWT`:

    curl -X "GET" <url_protected> -H 'Authorization: JWT <token>'


    ## Get con `login`:
    curl -X "POST" 'localhost:8000/get/my/token/' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username":"myuser", "password":"mypass"}'

    ## Others

    To get a pretty ouput when use `curl`, we can use or pipe the `json_pp` to pretty print the JSON output.
  5. Jonamaita revised this gist Jul 29, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion curl_post.md
    Original file line number Diff line number Diff line change
    @@ -112,4 +112,4 @@ with a data file

    To get a pretty ouput when use `curl`, we can use or pipe the `json_pp` to pretty print the JSON output.

    `curl https://api.cloudflare.com/client/v4/ | json_pp`
    curl https://api.cloudflare.com/client/v4/ | json_pp
  6. Jonamaita revised this gist Jul 29, 2021. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions curl_post.md
    Original file line number Diff line number Diff line change
    @@ -110,8 +110,6 @@ with a data file

    ## Others

    To get a pretty ouput when use `curl`, we can use or pipe the json_pp to pretty print the JSON output.
    To get a pretty ouput when use `curl`, we can use or pipe the `json_pp` to pretty print the JSON output.

    ```console
    curl https://api.cloudflare.com/client/v4/ | json_pp
    ```
    `curl https://api.cloudflare.com/client/v4/ | json_pp`
  7. Jonamaita revised this gist Jul 29, 2021. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions curl_post.md
    Original file line number Diff line number Diff line change
    @@ -108,3 +108,10 @@ with a data file
    curl -d "@data.json" -X POST http://localhost:3000/data


    ## Others

    To get a pretty ouput when use `curl`, we can use or pipe the json_pp to pretty print the JSON output.

    ```console
    curl https://api.cloudflare.com/client/v4/ | json_pp
    ```
  8. Jonamaita renamed this gist May 17, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @subfuzion subfuzion revised this gist Jun 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion curl.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    `-b, --cookie <name=data>`
    Supply cookie with request. If no `=`, then specifies the cookie file to use (see `-c`).

    `-c, --cokkie-jar <file name>`
    `-c, --cookie-jar <file name>`
    File to save response cookies to.

    `-d, --data <data>`
  10. @subfuzion subfuzion revised this gist Jun 12, 2016. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion curl.md
    Original file line number Diff line number Diff line change
    @@ -43,8 +43,13 @@
    `-s, --silent`
    Silent (quiet) mode. Use with `-S` to force it to show errors.

    `-v, verbose`
    `-v, --verbose`
    Provide more information (useful for debugging).

    `-w, --write-out <format>`
    Make curl display information on stdout after a completed transfer. See man page for more details on
    available variables. Convenient way to force curl to append a newline to output: `-w "\n"` (can add
    to `~/.curlrc`).

    `-X, --request`
    The request method to use.
  11. @subfuzion subfuzion revised this gist Jun 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion curl.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    `-f, --fail`
    Fail silently (don't output HTML error form if returned).

    `-F, --form <name=content>
    `-F, --form <name=content>`
    Submit form data.

    `-H, --header <header>`
  12. @subfuzion subfuzion revised this gist Jun 12, 2016. 1 changed file with 54 additions and 0 deletions.
    54 changes: 54 additions & 0 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,57 @@
    ## Common Options

    `-#, --progress-bar`
    Make curl display a simple progress bar instead of the more informational standard meter.

    `-b, --cookie <name=data>`
    Supply cookie with request. If no `=`, then specifies the cookie file to use (see `-c`).

    `-c, --cokkie-jar <file name>`
    File to save response cookies to.

    `-d, --data <data>`
    Send specified data in POST request. Details provided below.

    `-f, --fail`
    Fail silently (don't output HTML error form if returned).

    `-F, --form <name=content>
    Submit form data.

    `-H, --header <header>`
    Headers to supply with request.

    `-i, --include`
    Include HTTP headers in the output.

    `-I, --head`
    Fetch headers only.

    `-k, --insecure`
    Allow insecure connections to succeed.

    `-L, --location`
    Follow redirects.

    `-o, --output <file>`
    Write output to <file>. Can use `--create-dirs` in conjunction with this to create any directories
    specified in the `-o` path.

    `-O, --remote-name`
    Write output to file named like the remote file (only writes to current directory).

    `-s, --silent`
    Silent (quiet) mode. Use with `-S` to force it to show errors.

    `-v, verbose`
    Provide more information (useful for debugging).

    `-X, --request`
    The request method to use.


    ## POST

    When sending data via a POST or PUT request, two common formats (specified via the `Content-Type` header) are:
    * `application/json`
    * `application/x-www-form-urlencoded`
  13. @subfuzion subfuzion revised this gist May 13, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ For sending data with POST and PUT requests, these are common `curl` options:

    ## Examples

    ##### POST application/x-www-form-urlencoded
    ### POST application/x-www-form-urlencoded

    `application/x-www-form-urlencoded` is the default:

    @@ -40,7 +40,7 @@ with a data file

    curl -d "@data.txt" -X POST http://localhost:3000/data

    ##### POST application/json
    ### POST application/json

    curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

  14. @subfuzion subfuzion revised this gist May 13, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion curl.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ Many APIs will accept both formats, so if you're using `curl` at the command lin

    This gist provides examples for using both formats, including how to use sample data files in either format with your `curl` requests.

    ### curl usage
    ## curl usage

    For sending data with POST and PUT requests, these are common `curl` options:

    @@ -23,6 +23,8 @@ For sending data with POST and PUT requests, these are common `curl` options:
    * data
    * form urlencoded: `-d "param1=value1&param2=value2"` or `-d @data.txt`
    * json: `-d '{"key1":"value1", "key2":"value2"}'` or `-d @data.json`

    ## Examples

    ##### POST application/x-www-form-urlencoded

  15. @subfuzion subfuzion revised this gist May 13, 2016. 1 changed file with 18 additions and 2 deletions.
    20 changes: 18 additions & 2 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,28 @@ When sending data via a POST or PUT request, two common formats (specified via t
    * `application/json`
    * `application/x-www-form-urlencoded`

    Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the urlencoded format instead of json because
    Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the form urlencoded format instead of json because
    * the json format requires a bunch of extra quoting
    * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set
    * curl will send form urlencoded by default, so for json the `Content-Type` header must be explicitly set

    This gist provides examples for using both formats, including how to use sample data files in either format with your `curl` requests.

    ### curl usage

    For sending data with POST and PUT requests, these are common `curl` options:

    * request type
    * `-X POST`
    * `-X PUT`

    * content type header
    * `-H "Content-Type: application/x-www-form-urlencoded"`
    * `-H "Content-Type: application/json"`

    * data
    * form urlencoded: `-d "param1=value1&param2=value2"` or `-d @data.txt`
    * json: `-d '{"key1":"value1", "key2":"value2"}'` or `-d @data.json`

    ##### POST application/x-www-form-urlencoded

    `application/x-www-form-urlencoded` is the default:
  16. @subfuzion subfuzion revised this gist May 13, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ Many APIs will accept both formats, so if you're using `curl` at the command lin
    * the json format requires a bunch of extra quoting
    * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set

    This gist provides examples for using both formats, including how to use sample data files in either format with your `curl` requests.

    ##### POST application/x-www-form-urlencoded

  17. @subfuzion subfuzion revised this gist May 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion curl.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ When sending data via a POST or PUT request, two common formats (specified via t
    * `application/json`
    * `application/x-www-form-urlencoded`

    Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the urlencoded format than json because
    Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the urlencoded format instead of json because
    * the json format requires a bunch of extra quoting
    * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set

  18. @subfuzion subfuzion revised this gist May 13, 2016. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,12 @@
    When sending data via a POST or PUT request, two common formats (specified via the `Content-Type` header) are:
    * `application/json`
    * `application/x-www-form-urlencoded`

    Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the urlencoded format than json because
    * the json format requires a bunch of extra quoting
    * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set


    ##### POST application/x-www-form-urlencoded

    `application/x-www-form-urlencoded` is the default:
  19. @tonypujals tonypujals revised this gist Feb 26, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## POST application/x-www-form-urlencoded
    ##### POST application/x-www-form-urlencoded

    `application/x-www-form-urlencoded` is the default:

    @@ -12,7 +12,7 @@ with a data file

    curl -d "@data.txt" -X POST http://localhost:3000/data

    ## POST application/json
    ##### POST application/json

    curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

  20. @tonypujals tonypujals created this gist Feb 26, 2016.
    23 changes: 23 additions & 0 deletions curl.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    ## POST application/x-www-form-urlencoded

    `application/x-www-form-urlencoded` is the default:

    curl -d "param1=value1&param2=value2" -X POST http://localhost:3000/data

    explicit:

    curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data

    with a data file

    curl -d "@data.txt" -X POST http://localhost:3000/data

    ## POST application/json

    curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

    with a data file

    curl -d "@data.json" -X POST http://localhost:3000/data


    4 changes: 4 additions & 0 deletions data.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    {
    "key1":"value1",
    "key2":"value2"
    }
    1 change: 1 addition & 0 deletions data.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    param1=value1&param2=value2
    11 changes: 11 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    {
    "name": "postdemo",
    "version": "1.0.0",
    "scripts": {
    "start": "node server.js"
    },
    "dependencies": {
    "body-parser": "^1.15.0",
    "express": "^4.13.4"
    }
    }
    12 changes: 12 additions & 0 deletions server.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    var app = require('express')();
    var bodyParser = require('body-parser');

    app.use(bodyParser.json()); // for parsing application/json
    app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

    app.post('/data', function (req, res) {
    console.log(req.body);
    res.end();
    });

    app.listen(3000);