New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

syncano-client

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

syncano-client

Interact with your Syncano Sockets.

  • 0.2.1-4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55
increased by77.42%
Maintainers
2
Weekly downloads
 
Created
Source

XO code style CircleCI codecov

Syncano Client Library

This library enables you to interact with the Syncano Sockets via Javascript.

Getting started

Installing from NPM

npm install syncano-client --save

Also available at UNPKG

<script src="https://unpkg.com/syncano-client"></script>

Usage

The library supports the CommonJS syntax:

var Syncano = require('syncano-client');

You can also use it with ES6 modules:

import Syncano from 'syncano-client';

Creating a connection

To create a connection, simply initialize the Syncano object with instance name:

const s = new Syncano('MY_INSTANCE_NAME')

Constructor

Syncano(instanceName, options?)

ParameterTypeDescription
instanceNameStringSyncano instance name. You can create one using Syncano CLI.
optionsObjectOptional connection config.
options.hostStringSyncano host name.
options.tokenStringAllows you to initialize authorized connection.
options.loginMethodFunctionDefine custom login method

Methods

s(endpoint, data?, options?)

Alias of s.post method.

s.login(username, password)

Before you can send authorized requests, you need to login user with username and password. This method will automatically save user token for future requests.

s.login('john.doe', 'secret')
  .then(user => console.log(`Hello ${user.first_name}`))
  .catch(err => console.log('Invalid username or password.'))

s.logout()

Remove user token for future requests.

s.setToken(token)

Used to restore client session with token.

ParameterTypeDescription
tokenStringUser token used to authorize requests.

To remove token, call setToken without parameter:

s.setToken()

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

Send GET request to Syncano socket.

ParameterTypeDescription
endpointStringName of socket and endpoint joined with '/':
dataObjectOptional object send with request.
optionsObjectOptional request configuration.
// countries - socket name
// list - endpoint name
s.get('countries/list')

// Pass additional data to request
s.get('countries/list', { order_by: 'name' })

// Configure request
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.

s.subscribe(endpoint, callback)

Subscribe to given Syncano endpoint. Callback is fired each time you receive message from endpoint.

// chat - socket name
// messages/poll - endpoint name
s.subscribe('chat/messages/poll', message => {
  // Handle message
})

FAQs

Package last updated on 20 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc