coderitter-api-postonly-request
v1.0.4
Published
An adoption of the POSTonly HTTP client for the Coderitter API
Downloads
34
Readme
Coderitter API adopted POSTonly HTTP client for the browser
An adoption of the postonly-request package for the Coderitter API architecture. Also refer to the original documentation.
Related packages
As the original package, this one also uses the remote-method-call package but in the adjusted version for the Coderitter API.
This package uses knight-json to convert JavaScript objects together with their class information into JSON string and back into instances of the intended class.
Install
npm install coderitter-api-postonly-request
Overview
The Coderitter API version of this package needs you to input a RemoteMethodCall compatible object. The result is a Result object. Both are provided through the package coderitter-api-remote-method-call.
To be able to use the result you need to create a subclass of class Result.
class UserCreateResult extends Result {
constructor(public createdUser: User) {
super()
}
}Through the use of knight-json the function expects a third parameter instantiator which is a mapping of class names to methods that instantiate the corresponding classes.
let instantiator = {
'User': () => new User
'UserCreateResult': () => new UserCreateResult
}Now you can make the request.
import { request } from 'postonly-request'
// remote method call object
let remoteMethodCall: RemoteMethodCall = {
methodName: 'User.create',
parameter: user
}
let result: UserCreateResult = await request('https://company.com/api_v1', remoteMethodCall, instantiator)
// response is an instance of class UserCreateResult
result == {
type: 'value',
// createdUser is an instance of class User
createdUser: {
id: 1,
name: 'Ruben'
}
}