Add basic auth sample.

This commit is contained in:
jcamiel 2021-11-20 20:27:44 +01:00 committed by jcamiel
parent f26c2c57e4
commit d33b95a63a

View File

@ -153,6 +153,7 @@ Table of Contents
================= =================
* [Samples](#samples) * [Samples](#samples)
* [Getting Data](#getting-data) * [Getting Data](#getting-data)
* [HTTP Headers](#http-headers)
* [Query Params](#query-params) * [Query Params](#query-params)
* [Sending Data](#sending-data) * [Sending Data](#sending-data)
* [Sending HTML Form Datas](#sending-html-form-datas) * [Sending HTML Form Datas](#sending-html-form-datas)
@ -201,7 +202,7 @@ Table of Contents
To run a sample, you can edit a file with the sample content, and use Hurl: To run a sample, you can edit a file with the sample content, and use Hurl:
``` ```shell
$ vi sample.hurl $ vi sample.hurl
GET https://example.net GET https://example.net
@ -220,6 +221,8 @@ GET https://example.net
[Doc](https://hurl.dev/docs/request.html#method) [Doc](https://hurl.dev/docs/request.html#method)
### HTTP Headers
A simple GET with headers: A simple GET with headers:
```hurl ```hurl
@ -233,6 +236,25 @@ Connection: keep-alive
[Doc](https://hurl.dev/docs/request.html#headers) [Doc](https://hurl.dev/docs/request.html#headers)
Headers can be used to perform [Basic authentication]. Given a login `bob`
with password `secret`:
In a shell:
```shell
$ echo -n 'bob:secret' | base64
Ym9iOnNlY3JldA==
```
Then, use [`Authorization` header] to add basic authentication to a request:
```hurl
GET https://example.com/protected
Authorization: Basic Ym9iOnNlY3JldA==
```
Alternatively, on can use [`--user` option].
### Query Params ### Query Params
```hurl ```hurl
@ -329,7 +351,7 @@ Content-Type: application/json
Variables can be initialized via command line: Variables can be initialized via command line:
```bash ```shell
$ hurl --variable key0=apple \ $ hurl --variable key0=apple \
--variable key1=true \ --variable key1=true \
--variable key2=null \ --variable key2=null \
@ -382,10 +404,10 @@ header "Location" contains "www.example.net"
### Testing REST Apis ### Testing REST Apis
Asserting JSON body response with [JSONPath]: Asserting JSON body response (node values, collection count etc...) with [JSONPath]:
```hurl ```hurl
GET https//example.org/order GET https://example.org/order
screencapability: low screencapability: low
HTTP/1.1 200 HTTP/1.1 200
@ -403,7 +425,7 @@ jsonpath "$.state" != null
Testing status code: Testing status code:
```hurl ```hurl
GET https//example.org/order/435 GET https://example.org/order/435
HTTP/1.1 200 HTTP/1.1 200
``` ```
@ -411,7 +433,7 @@ HTTP/1.1 200
[Doc](https://hurl.dev/docs/asserting-response.html#version-status) [Doc](https://hurl.dev/docs/asserting-response.html#version-status)
```hurl ```hurl
GET https//example.org/order/435 GET https://example.org/order/435
# Testing status code is in a 200-300 range # Testing status code is in a 200-300 range
HTTP/1.1 * HTTP/1.1 *
@ -745,11 +767,11 @@ curl(1) hurlfmt(1)
Precompiled binary is available at [hurl-1.4.0-x86_64-linux.tar.gz]: Precompiled binary is available at [hurl-1.4.0-x86_64-linux.tar.gz]:
```shell ```shell
INSTALL_DIR=/tmp $ INSTALL_DIR=/tmp
curl -sL https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl-1.4.0-x86_64-linux.tar.gz | tar xvz -C $INSTALL_DIR $ curl -sL https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl-1.4.0-x86_64-linux.tar.gz | tar xvz -C $INSTALL_DIR
export PATH=$INSTALL_DIR/hurl-1.4.0:$PATH $ export PATH=$INSTALL_DIR/hurl-1.4.0:$PATH
hurl --version $ hurl --version
hurl 1.4.0 hurl 1.4.0
``` ```
@ -758,8 +780,8 @@ hurl 1.4.0
For Debian / Ubuntu, Hurl can be installed using a binary .deb file provided in each Hurl release. For Debian / Ubuntu, Hurl can be installed using a binary .deb file provided in each Hurl release.
```shell ```shell
curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl_1.4.0_amd64.deb $ curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl_1.4.0_amd64.deb
sudo dpkg -i hurl_1.4.0_amd64.deb $ sudo dpkg -i hurl_1.4.0_amd64.deb
``` ```
#### Arch Linux / Manjaro #### Arch Linux / Manjaro
@ -773,10 +795,10 @@ Precompiled binary is available at [hurl-1.4.0-x86_64-osx.tar.gz].
Hurl can also be installed with [Homebrew]: Hurl can also be installed with [Homebrew]:
```shell ```shell
brew tap jcamiel/hurl $ brew tap jcamiel/hurl
brew install hurl $ brew install hurl
hurl --version $ hurl --version
hurl 1.4.0 hurl 1.4.0
``` ```
@ -792,28 +814,28 @@ An installer [hurl-1.4.0-win64-installer.exe] is also available.
#### Chocolatey #### Chocolatey
``` ```shell
choco install hurl $ choco install hurl
``` ```
#### Scoop #### Scoop
``` ```shell
scoop install hurl $ scoop install hurl
``` ```
#### Windows Package Manager #### Windows Package Manager
``` ```shell
winget install hurl $ winget install hurl
``` ```
### Cargo ### Cargo
If you're a Rust programmer, Hurl can be installed with cargo. If you're a Rust programmer, Hurl can be installed with cargo.
``` ```shell
cargo install hurl $ cargo install hurl
``` ```
## Building From Sources ## Building From Sources
@ -838,19 +860,19 @@ pacman -Sy --noconfirm pkgconf gcc openssl libxml2
Hurl is written in [Rust]. You should [install] the latest stable release. Hurl is written in [Rust]. You should [install] the latest stable release.
```shell ```shell
curl https://sh.rustup.rs -sSf | sh -s -- -y $ curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env $ source $HOME/.cargo/env
rustc --version $ rustc --version
cargo --version $ cargo --version
``` ```
Build Build
```shell ```shell
git clone https://github.com/Orange-OpenSource/hurl $ git clone https://github.com/Orange-OpenSource/hurl
cd hurl $ cd hurl
cargo build --release $ cargo build --release
./target/release/hurl --version $ ./target/release/hurl --version
``` ```
### Build on Windows ### Build on Windows
@ -875,6 +897,9 @@ Please follow the [contrib on Windows section].
[raw string body]: https://hurl.dev/docs/request.html#raw-string-body [raw string body]: https://hurl.dev/docs/request.html#raw-string-body
[predicates]: https://hurl.dev/docs/asserting-response.html#predicates [predicates]: https://hurl.dev/docs/asserting-response.html#predicates
[JSONPath]: https://goessner.net/articles/JsonPath/ [JSONPath]: https://goessner.net/articles/JsonPath/
[Basic authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#basic_authentication_scheme
[`Authorization` header]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
[`--user` option]: https://hurl.dev/docs/man-page.html#user
[GitHub]: https://github.com/Orange-OpenSource/hurl [GitHub]: https://github.com/Orange-OpenSource/hurl
[hurl-1.4.0-win64.zip]: https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl-1.4.0-win64.zip [hurl-1.4.0-win64.zip]: https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl-1.4.0-win64.zip
[hurl-1.4.0-win64-installer.exe]: https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl-1.4.0-win64-installer.exe [hurl-1.4.0-win64-installer.exe]: https://github.com/Orange-OpenSource/hurl/releases/download/1.4.0/hurl-1.4.0-win64-installer.exe