Home Reference Source Test Repository
import RestConnection from 'eloquentjs/src/Connection/RestConnection.js'
public class | source

RestConnection

RestConnection

This sends queries to a given endpoint over HTTP using RESTful conventions. If additional query methods are called, these are encoded in the (http) query string.

The endpoint must be set before this connection is used.

Constructor Summary

Public Constructor
public

constructor(endpoint: string)

Create a new RestConnection

Member Summary

Protected Members
protected

The base URL for this connection.

Method Summary

Public Methods
public

buildOptions(method: string, data: Object, options: Object): Object

Get an options hash for the fetch init parameter.

public

buildUrl(suffix: string | number | array): string

Get endpoint URL with the entity ID or query data appended.

public

Run an INSERT query.

public

delete(idOrQuery: number | Array): Promise

Run a DELETE query.

public

read(idOrQuery: number | Array): Promise

Run a SELECT query.

public

sendRequest(urlSuffix: string | number | Array, method: string, body: Object): Promise

Send an HTTP request and return a Promise.

public

unwrap(response: Response): Object

Take a fetch response and extract the JSON.

public

update(idOrQuery: number | Array, data: Object): Promise

Run an UPDATE query.

public

url(id: number, query: array): string

Get a URL to the endpoint.

Public Constructors

public constructor(endpoint: string) source

Create a new RestConnection

Params:

NameTypeAttributeDescription
endpoint string
  • optional

Protected Members

protected endpoint: string source

The base URL for this connection.

Public Methods

public buildOptions(method: string, data: Object, options: Object): Object source

Get an options hash for the fetch init parameter.

Params:

NameTypeAttributeDescription
method string
  • optional
data Object
  • optional
options Object
  • optional

Return:

Object

See:

public buildUrl(suffix: string | number | array): string source

Get endpoint URL with the entity ID or query data appended.

Params:

NameTypeAttributeDescription
suffix string | number | array

Return:

string

public create(data: Object): Promise source

Run an INSERT query.

Params:

NameTypeAttributeDescription
data Object

Return:

Promise

Test:

public delete(idOrQuery: number | Array): Promise source

Run a DELETE query.

Params:

NameTypeAttributeDescription
idOrQuery number | Array

Return:

Promise

Test:

public read(idOrQuery: number | Array): Promise source

Run a SELECT query.

Params:

NameTypeAttributeDescription
idOrQuery number | Array

Return:

Promise

Test:

public sendRequest(urlSuffix: string | number | Array, method: string, body: Object): Promise source

Send an HTTP request and return a Promise.

Params:

NameTypeAttributeDescription
urlSuffix string | number | Array
  • optional
method string
  • optional
body Object
  • optional

Return:

Promise

public unwrap(response: Response): Object source

Take a fetch response and extract the JSON.

Params:

NameTypeAttributeDescription
response Response

Return:

Object

public update(idOrQuery: number | Array, data: Object): Promise source

Run an UPDATE query.

Params:

NameTypeAttributeDescription
idOrQuery number | Array
data Object

Return:

Promise

Test:

public url(id: number, query: array): string source

Get a URL to the endpoint.

Params:

NameTypeAttributeDescription
id number
  • optional
query array
  • optional

Return:

string