Source the script

You must source the http.class.sh. Then its functions are usable in the current process. The “methods” start with “http” dot “[method]”.

Initialize a new request

http.init

Make a request

http.makeRequest 'http://www.example.com/'

This stores the response in a variable and has no output.

Use http.* functions

Now you can get its data, eg

  • http.getStatuscode - This returns the Http status code
  • http.getStatus - This returns a string - one of Ok|Redirect|Error
  • http.getResponseHeader - print Http response header
  • http.getResponse - get response body

Example script

#!/bin/bash

cd "$( dirname "$0" )" || exit
. ../http.class.sh || exit 1

http.init
http.makeRequest GET "http://www.example.com/"

http.getStatuscode
http.getResponseHeader

A single request shows no advantages yet. You need authentication? You make multiple requests to the same API? Then you should continue.

Try it

Execute the script ./tests/example_01_simple_get.sh to see a basic example.

Screenshot - example script