pub struct HTTPLibrary {
pub agent: Agent,
}Fields§
§agent: AgentTrait Implementations§
Source§impl Debug for HTTPLibrary
impl Debug for HTTPLibrary
Source§impl Default for HTTPLibrary
impl Default for HTTPLibrary
Source§impl Library for HTTPLibrary
impl Library for HTTPLibrary
Source§fn scope(&self) -> String
fn scope(&self) -> String
Scope of this library.
This is how this library is invoked from Stof.
Ex. HTTP.get('https://example.com')
Source§fn call(
&self,
pid: &str,
doc: &mut SDoc,
name: &str,
parameters: &mut Vec<SVal>,
) -> Result<SVal, SError>
fn call( &self, pid: &str, doc: &mut SDoc, name: &str, parameters: &mut Vec<SVal>, ) -> Result<SVal, SError>
Call an HTTP method in this library. Returns (status code: int, headers: map, body: blob).
Supported functions:
-
HTTP.ok - check to see if a status code is OK (in range 200-299)
-
HTTP.clientError - check to see if a status code is 400-499
-
HTTP.serverError - check to see if a status code is 500-599
-
HTTP.contentType - get content type from a header map
-
HTTP.send - must take an additional parameter at first (one of below methods).
-
HTTP.get
-
HTTP.head
-
HTTP.patch
-
HTTP.post
-
HTTP.put
-
HTTP.delete
Parameters (in order) for each call:
- url: str - The HTTP request path (REQUIRED)
- headers: vec[(str, str)] | map - The request headers (OPTIONAL)
- body: str | blob - The request body (OPTIONAL)
- timeout: float | units - The overall timeout for the request (OPTIONAL) (default 5 seconds - use time units as needed)
- response_obj: obj - A response object to parse the response into via doc.header_import with the content type (OPTIONAL)
Basic GET request: HTTP.get('https://example.com')
POST request with a body: HTTP.post('https://example.com', 'this is a string body to send')
POST request json body and a timeout: HTTP.post('https://example.com', map(('content-type', 'application/json')), stringify(self, 'json'), 10s)