Skip to content
This repository has been archived by the owner on Dec 24, 2021. It is now read-only.

Latest commit

History

History
83 lines (65 loc) 路 1.9 KB

v2.md

File metadata and controls

83 lines (65 loc) 路 1.9 KB

Migrating from v2

This is the migration guide for upgrading from v1 to v2 of Orchid.

Changelog

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.raw() -> Response.buffer()
  • Response.isEmpty -> Response.empty

Serialization

Orchid allows you to serialize your own data without doing it yourself every time you make a request. Currently, this is only limited to Response.body().

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
  }
};