HTTPClient

Robot Framework library documentation

HTTPClient Documentation

Version 2.0.0 Scope GLOBAL 13 Keywords
Author: Peter ParkerMaintainer: API TeamLicense: BSD-3-ClauseRobot Framework: >=5.0Python: >=3.10
Sample Usage
Robot
*** Settings ***
Library    HTTPClient

*** Test Cases ***
Example
    [Documentation]    Demonstrates using HTTPClient
    # add your keyword calls here

Introduction

HTTP client library for Robot Framework.

This library provides keywords for:

  • Making HTTP requests (GET, POST, PUT, DELETE)
  • Handling HTTP responses
  • Working with JSON APIs
  • Managing headers and authentication
  • Response validation

Arguments

url : str
headers : Optional[Dict[str, str]] default: None

Return Type

Dict[str, Any]

Documentation

Perform HTTP GET request.

Arguments:

  • url: Target URL
  • headers: Optional dictionary of HTTP headers

Returns: Response dictionary with status, headers, and body

Example:

*** Settings ***
Library    HTTPClient


*** Test Cases ***
HTTP GET Example
    ${response}    Http Get    https://api.example.com/users
    Should Be Equal As Integers     ${response}[status]    200

Arguments

url : str
data : Optional[Dict[str, Any]] default: None
headers : Optional[Dict[str, str]] default: None

Return Type

Dict[str, Any]

Documentation

Perform HTTP POST request.

Arguments:

  • url: Target URL
  • data: Request body data (dictionary)
  • headers: Optional dictionary of HTTP headers

Returns: Response dictionary with status, headers, and body

Example:

*** Settings ***
Library    HTTPClient


*** Test Cases ***
HTTP POST Example
    ${data}    Create Dictionary    name=John    email=john@example.com
    ${response}    Http Post    https://api.example.com/users    ${data}
    Response Should Be Success     ${response}

Arguments

url : str
data : Optional[Dict[str, Any]] default: None
headers : Optional[Dict[str, str]] default: None

Return Type

Dict[str, Any]

Documentation

Perform HTTP PUT request.

Arguments:

  • url: Target URL
  • data: Request body data (dictionary)
  • headers: Optional dictionary of HTTP headers

Returns: Response dictionary with status, headers, and body

Arguments

url : str
headers : Optional[Dict[str, str]] default: None

Return Type

Dict[str, Any]

Documentation

Perform HTTP DELETE request.

Arguments:

  • url: Target URL
  • headers: Optional dictionary of HTTP headers

Returns: Response dictionary with status, headers, and body

Arguments

name : str
value : str

Documentation

Set a default header for all subsequent requests.

Arguments:

  • name: Header name
  • value: Header value

Example:

*** Settings ***
Library    HTTPClient


*** Test Cases ***
Set Header Example
    Set Header     Authorization    Bearer token123
    Set Header     Content-Type    application/json
    ${response}    Http Get    https://api.example.com/data

Documentation

Clear all default headers.

Arguments

response : Dict[str, Any]

Return Type

int

Documentation

Extract HTTP status code from response.

Arguments:

  • response: Response dictionary from HTTP request

Returns: HTTP status code

Arguments

response : Dict[str, Any]

Return Type

Dict[str, Any]

Documentation

Extract response body from HTTP response.

Arguments:

  • response: Response dictionary from HTTP request

Returns: Response body as dictionary

Arguments

response : Dict[str, Any]

Documentation

Verify that HTTP response status is success (2xx).

Arguments:

  • response: Response dictionary from HTTP request

Raises: AssertionError if status is not 2xx

Arguments

response : Dict[str, Any]

Return Type

Dict[str, Any]

Documentation

Parse JSON response body.

Arguments:

  • response: Response dictionary from HTTP request

Returns: Parsed JSON as dictionary

Arguments

params : Dict[str, Any]

Return Type

str

Documentation

Build URL query string from parameters.

Arguments:

  • params: Dictionary of query parameters

Returns: Query string (e.g., "key1=value1&key2=value2")

Example:

*** Settings ***
Library    HTTPClient


*** Test Cases ***
Build Query String Example
    ${params}    Create Dictionary    page=1    limit=10
    ${query}    Build Query String    ${params}
    Should Be Equal     ${query}    page=1&limit=10

Arguments

username : str
password : str

Documentation

Set Basic Authentication header.

Arguments:

  • username: Username for authentication
  • password: Password for authentication

Example:

*** Settings ***
Library    HTTPClient


*** Test Cases ***
Set Basic Auth Example
    Set Basic Auth     admin    secret123
    ${response}    Http Get    https://api.example.com/protected

Arguments

token : str

Documentation

Set Bearer token authentication header.

Arguments:

  • token: Bearer token string

Example:

*** Settings ***
Library    HTTPClient


*** Test Cases ***
Set Bearer Token Example
    Set Bearer Token     eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
    ${response}    Http Get    https://api.example.com/data

Need Help?

Found an issue or have a feature request for this library? Let the maintainers know by opening a new GitHub issue. Please include environment details and relevant log output to help us reproduce the problem.

Open an Issue on GitHub