URL HTTP Client
The Ioto URL API is a HTTP client for interacting with HTTP servers. It is a full-duplex streaming HTTP client that can retrieve both documents and live streaming data.
The URL client is a highly efficient, compact HTTP client that uses minimal CPU from only 7K of code.
The URL API uses a fiber coroutines to that you can write natural, blocking, procedural code without ugly callbacks or complex threads.
- HTTP/1.0, HTTP.1.1 client.
- Fully streaming API for dynamic input and output.
- Convenience JSON API for interacting with REST services.
- Single-threaded, fiber coroutine event-based runtime without ugly callbacks or complex threads.
- TLS/SSL 1.3 with certificate verification controls.
API Quick Tour
The URL API provides a high-level simple API and a lower-level API with more granular control.
The low-level API consists of the routines urlGet and urlPost.
To get a remote document, use the urlGet API:
This call will block the current fiber while other fibers continue to run. When the document has been retrieved, the call will resume and the document will be returned. If the request fails and a non-200 HTTP status is returned, the call returns NULL.
When complete, you must free the returned string using rfree.
To issue a post request, use urlPost API
If the data is a string, you can set the length to be -1 and the length will be calculated from the string.
If you want to issue a POST request and retrieve a JSON document, you can use the JSON variants urlPostJson:
Use the JSON APIs to manage the returned JSON in-memory tree result.
To supply headers with your requests, you can use the headers printf style arguments:
Each header in the format string must be separated by "\r\n".
Low Level API
To use the low-level API, first create a URL instance via urlAlloc:
When finished, free the URL with urlClose.
The primary low-level API is urlFetch. This API supports issuing any HTTP method with body data and headers.
This call returns a HTTP status code. To retrieve the returned data, use urlGetResponse or urlGetJsonResponse:
You can also use the JSON variant urlFetchJson which returns the JSON tree if the HTTP return status is a successful 200 code.
In this case, you can call urlGetStatus to return the HTTP status code.
To retrieve returned HTTP headers, use urlGetHeader:
The Ioto URL client fully supports streaming data in both directions.
To start a streaming request, use urlStart. Then write data blocks with urlWrite.
When complete, write a NULL block to signify the end of the posted data.
To stream the response, use urlRead:
You can define a timeout limit for URL requests incase the server should hang.