Generic HTTP Adapter
Last updated
Last updated
This is a generic HTTP adapter that can connect with a variety of different systems using the Python requests library.
Field | Description | Example |
---|---|---|
Field | Description | Example |
---|---|---|
the adapter attempts to parse the relevant content for the user based on the ‘content-type’ response header. These align with the force_response_content_type
on the field mappings.
Host
REQUIRED | Host of web server (note: web server is expected to use “https”).
The adapter assumes HTTPS is to be used. Unsecure HTTP is not supported.
Do not include any path components besides the domain name of the host (use www.example.com
not https://www.example.com/some/path
)
www.example.com
Basic Auth Username
OPTIONAL | Username for authenticating with remote host.
Mozilla docs: HTTP authentication - Basic authentication scheme
test-user
Basic Auth Password
OPTIONAL | Password for authenticating with remote host.
*********
Server Auth Cert
OPTIONAL | Certificate used to verify the identity of the remote server.
Certificates can come in many filetypes: .der
, .cer
, .crt
, .cert
, .pem
, .p12
, .pfx
Password protected .pfx
/ .p12
certificates are not currently supported.
server_certificate.cer
Client Auth Cert
OPTIONAL | Certificate used to verify the identity of the requestor (Glyue) to the remote server.
client_certificate.pem
Timeout Seconds
REQUIRED | The number of seconds before the connection should time out. Min 1, max 120, default 60.
60
url_path
REQUIRED | str
| URL path to use with host.
'/test/example'
method
REQUIRED | str
| HTTP method to use in request.
'POST'
body
OPTIONAL | multiple types
| Payload in the request.
Setting a dict
as the value will make the adapter set the Content-Type
header to application/x-www-form-urlencoded
.
To send JSON data, import the json
module and use json.dumps(value)
.
JSON: json.dumps({'key': "value"})
Form data: {'key': "value"}
params
OPTIONAL | dict
| Key-value pairs to send as query parameters.
{'search': "foo", 'page': "3"}
params.search : "foo"
params.page : "3"
Resulting URL: https://www.example.com/url/path?search=foo,page=3
headers
OPTIONAL | dict
| Key-value pairs representing headers for the request.
Consider using the Content-Type
header to tell the remote host the type of content you are sending and/or the Accept
header to tell the remote server what type of content you are willing/able to receive.
Hyphens do not work with dot.notation
so please use ['bracket-notation']
in this case.
References
headers['Content-Type'] : "application/json"
headers.Accept : "application/octet-stream"
auth
OPTIONAL | tuple
| Username and password used for basic authentication.
This overrides the Adapter Config Basic Auth Username and Password and should only be used in special circumstances.
For more info, please see the documentation on requests
Basic Authentication features.
('username', 'p@$$w0rd')
force_response_content_type
OPTIONAL | str
| Force the adapter to parse the response content in a certain way.
If not specified, the adapter dynamically parses the response according to its Content-Type
header.
This optional field is likely unnecessary, but is nonetheless available for unique circumstances that may arise.
"json"
| Adapter will parse the response as JSON, regardless of the response Content-Type
header.
Returns JSON-like Python object, usually dict
, list
, but possibly str
, int
or float
.
"xml"
| Adapter will parse the response as XML, regardless of the response Content-Type
header.
Returns a dict
representing the XML data structure, following the same standard as most (if not all) Glyue XML adapters.
"text"
| Adapter will parse the response as plaintext, regardless of the response Content-Type
header.
Returns a str
.
"bytes"
| Adapter will parse the response as binary data, regardless of the response Content-Type
header.
Returns bytes
Using "json"
will call the requests
Response.json()
method when parsing the response, and will raise an exception if the response is not valid JSON, causing the Service Request to fail.
Using "xml"
will call the django_glyue_app.utils.xml_to_adapter_payload()
method when parsing the response, and will raise an exception if the response is not valid XML, causing the Service Request to fail.
Using "text"
or "bytes"
should never raise an exception, and generally safe to use in all circumstances.
"json"
"xml"
"text"
"bytes"