Module ngx-oauth.http_client

Adapter for HTTP client.

Functions

request (method, headers, url, body) Sends an HTTP request and returns a response.
request_json (method, headers, url, body) Sends an HTTP request and returns a parsed JSON body (wrapped in Right) if response status is 200; otherwise returns an error message (wrapped in Left).
get_for_json (url, bearer_token) Sends an HTTP GET request with optional Bearer token (OAuth 2.0 access token) and returns a parsed JSON body (wrapped in Right) if response status is 200; otherwise returns an error message (wrapped in Left).
post_form_for_json (headers, url, form_data) Sends an HTTP POST request with body encoded as x-www-form-urlencoded and returns a parsed JSON body (wrapped in Right) if response status is 200; otherwise returns an error message (wrapped in Left).


Functions

request (method, headers, url, body)

Sends an HTTP request and returns a response.

If the request is successful, response wrapped in Right will contain the following fields:

  • status: The status code.
  • headers: A table of headers.
  • body: The response body as a string.

Parameters:

Returns:

    Either Right with a response, or Left with an error message.
request_json (method, headers, url, body)
Sends an HTTP request and returns a parsed JSON body (wrapped in Right) if response status is 200; otherwise returns an error message (wrapped in Left). This method accepts the same arguments as request.

Parameters:

  • method
  • headers
  • url
  • body

Returns:

    Either Right with parsed JSON body in a table, or Left with an error message.
get_for_json (url, bearer_token)
Sends an HTTP GET request with optional Bearer token (OAuth 2.0 access token) and returns a parsed JSON body (wrapped in Right) if response status is 200; otherwise returns an error message (wrapped in Left).

Parameters:

  • url string The request's URL.
  • bearer_token optional string The Bearer token to be added into Authorization header.

Returns:

    Either Right with parsed JSON body in a table, or Left with an error message.
post_form_for_json (headers, url, form_data)
Sends an HTTP POST request with body encoded as x-www-form-urlencoded and returns a parsed JSON body (wrapped in Right) if response status is 200; otherwise returns an error message (wrapped in Left).

Parameters:

Returns:

    Either Right with parsed JSON body in a table, or Left with an error message.
generated by LDoc 1.4.3