Additions
- Better Middleware API
- Serialization API
- Added
Response.body()
to use the Serialization API
Fixes
- multipart/form-data Support
Deprecated stuff
Response.successful
->Response.success
Response.isEmpty
->Response.empty
Serialization
Orchid allows you to serialize your own data without doing it yourself every time you make a request.
An example on building a XML serializer would look like this:
const { Serializer } = require('@augu/orchid');
module.exports = class XMLSerializer extends Serializer {
constructor() {
super(/application\/xhtml[+]xml/gi);
}
serialize(data) {
const str = data.toString();
return someXMLParser(str);
}
}
Then we inject it into our http client or adding it with orchid#method
// HttpClient
const client = new HttpClient({
serializers: [new XMLSerializer()]
});
// Method function
orchid.get({
serializers: [new XMLSerializer()]
});
Better Middleware API
Orchid now has a new middleware API that is executed on different types. The old API would look like this:
const { CycleType } = require('@augu/orchid');
module.exports = () => ({
cycleType: CycleType.Execute,
name: 'my:mid',
intertwine() {
// Now we do stuff here, we don't add the middleware since it does itself
}
});
This is not an ideal API to use because it didn't support more than 1 type and naming conventions didn't make sense. The new API would look like this:
const { MiddlewareType } = require('@augu/orchid');
module.exports = {
type: [MiddlewareType.None],
name: 'name',
run(client, type) {
// this => this middleware
// client => The HttpClient used
// type => The middleware type
}
};