You are viewing an older revision! See the latest version
HTTP Client Data Containers
Data Containers¶
There are four containers included in the HttpClient package:
- HttpText
- HttpMap
- HttpFile
- HttpStream
You can also create your own by simply inheriting the HttpData class.
HttpText¶
This is a simple "Text" data repository.
Reference¶
HttpText(const string& encoding = "text/html")
Instantiates the object. You can set the encoding of the data here, it defaults to text/html.
const char* gets() const
Returns the text in the container as a zero-terminated char*. The array returned points to the internal buffer of the object and remains owned by the object.
void puts(const char* str)
Sets the text in the container using a zero-terminated char*.
string& get()
Returns the text in the container as string.
void set(const string& str)
Sets the text in the container as string.
Examples¶
The Working with the networking stack article's first example uses HttpText.
HttpMap¶
This class simplifies the use of key/value pairs requests and responses used widely among web APIs.
Inheritance¶
Note that HttpMap inherits from std::map<std::string,std::string>. You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value.
Reference¶
HttpMap()
Instantiates the object.
Examples¶
The Twitter example uses HttpMap.
HttpFile¶
This is class provides file access/storage for HTTP requests and responses data payloads.
Reference¶
HttpFile(const char* path)
Instantiates the object. Opens file at path path. It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance.
Note that you must choose the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing.
Information
Note that to use this you must instantiate a proper file system (such as the LocalFileSystem or the SDFileSystem).
Examples¶
HttpStream¶
This class allows you to stream data from the web using a persisting HTTP connection. To use it properly you must use a non-blocking HttpClient method.
Reference¶
HttpStream()
Instantiates the object.
void readNext(byte* buf, int size)
Passes a buffer of address buf and size size to the instance. When it receives data it will be stored in this buffer. When the buffer is full it throttles the client until this function is called again.
bool readable()
Returns true if there is data available to read.
int readLen()
Returns the actual length of the payload written in the buffer.
Examples¶
None yet, but coming soon...