Skip to content

Latest commit

 

History

History
93 lines (67 loc) · 3.42 KB

requests.md

File metadata and controls

93 lines (67 loc) · 3.42 KB

Requests

Easy way to call Syncano Sockets.

Methods

Name Description
Syncano Create Syncano connection
s Send POST request
s.get Send GET request
s.post Send POST request
s.patch Send PATCH request
s.put Send PUT request
s.delete Send DELETE request

Syncano(instanceName, options?)

Type Name Default Description
string instanceName undefined Syncano Instance name. You can create one using Syncano CLI
object options {} Additional connection options
string options.host syncano.space Syncano host name.
string options.token undefined Allows you to initialize authorized connection.
string options.transformResponse undefined Define custom response format. (EXPERIMENTAL)

Create connection

const s = new Syncano('INSTANCE_NAME')

s.get(endpoint, data?, options?)

Type Name Default Description
string endpoint undefined Name of socket and endpoint joined with '/'
object/FormData data {} Optional object send with request
object options {} Optional request configuration, see axios options
string options.headers {} Request headers

Send GET request to Syncano Socket.

Simple Request

// countries - socket name
// list - endpoint name
s.get('countries/list')
  .then(res => {
    // Handle response
  })
  .catch(err => {
    // Handle error
  })

Pass additional data to request

s.get('countries/list', { order_by: 'name' })

Send request with headers

s.get('countries/list', {}, {
  headers: {
    'Content-Type': 'application/json'
  }
})

For more options, view axios documentation

s.post(endpoint, data?, options?)

Send POST request to Syncano Socket. View s.get method for more info.

s.delete(endpoint, data?, options?)

Send DELETE request to Syncano Socket. View s.get method for more info.

s.put(endpoint, data?, options?)

Send PUT request to Syncano Socket. View s.get method for more info.

s.patch(endpoint, data?, options?)

Send PATCH request to Syncano Socket. View s.get method for more info.