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:
- method string The HTTP method (e.g. GET, POST, HEAD, ...).
- headers {[string]=string,...} The request's headers.
- url string The request's URL.
- body string The request's body as string.
Returns:
- 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 inLeft
). This method accepts the same arguments as request.Parameters:
- method
- headers
- url
- body
Returns:
- 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 inLeft
).Parameters:
- url string The request's URL.
- bearer_token
optional string
The Bearer token to be added into
Authorization
header.
Returns:
- 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 inRight
) if response status is 200; otherwise returns an error message (wrapped inLeft
).Parameters:
- headers {[string]=string,...} The request's headers.
- url string The request's URL.
- form_data {[string]=string,...} The form data as a table.
Returns: