Service Drivers
Service drivers interface with devices that communicate using the HTTP(S) protocol. Currently HTTP versions 1.0 and 1.1 are supported.
They are similar to Device Drivers with two major differences:
It’s not recommended to use the common
received
functionThey do not have a
send
function
This is because HTTP is much more contextual than many protocols. It’ll often only return success whereas many custom device protocol responses can be interpreted without knowledge of the original request.
Sending a Request
Each request should either set the on_receive
callback option or provide a block for response processing.
Method | Arguments | Description |
request | verb, path, options = {}, &blk | allows you to pass in a custom verb |
get | path, options = {}, &blk | |
post | path, options = {}, &blk | |
put | path, options = {}, &blk | |
delete | path, options = {}, &blk |
Request Options
Option | Example | Effect |
|
| URI?me=bob&other=rain |
|
| when body is a string it will be sent as is. When a hash, it will be form encoded. |
|
| Some headers are transformed further. See bellow |
|
| Will send the file as the body |
|
| Will close the connection once the request has completed |
|
| Will perform a request with an endpoint that requires NTLM auth |
|
| Will perform a request with an endpoint that requires digest auth |
|
| Use a proxy server for the request. |
NOTE:: Both NTLM and Digest auth are challenge response protocols and won’t work with HTTP 1.0 or keep alive false
Basic Authentication
Basic auth is supported natively along with NTLM and digest authentication techniques. All that is required is to set the authorization
header like so:
For more advanced methods of authentication see Utilities and Helpers.
Handling a Response
The response object is passed to your received block and looks like this:
Cookies
Cookies are handled in the background in the same way a browser would handle cookies.
There is a helper method that can be used to clear cookies: clear_cookies
You can set cookies by setting the cookie
header field. Supports both strings and hashes.
Proxy Support
When building drivers that need to communicate with external endpoints, its good practice to provide proxy support. This can be achieved by passing the proxy
parameter with requests. To provide user support of these, these can be loaded from settings and set as part of the defaults for every request.
Last updated