Options
All
  • Public
  • Public/Protected
  • All
Menu

sutro-client NPM version Downloads Build Status

A simple and sugary client for using sutro APIs.

Install

npm install sutro-client --save

Example

sutro Server

{
  user: {
    create: async ({ data }) => User.create(data),
    find: async ({ options }) => User.findAll(options),
    findById: async ({ userId }) => User.findById(userId),
    updateById: async ({ userId, data }) => User.updateById(userId, data),
    replaceById: async ({ userId, data }) => User.replaceById(userId, data),
    deleteById: async ({ userId }) => User.deleteById(userId),

    friend: {
      create: async ({ userId, data }) => {
        const me = await User.findById(userId)
        await me.addFriend(data)
        return me
      },
      find: async ({ userId, options }) => {
        const me = await User.findById(userId)
        return me.findFriends(options)
      },
      findById: async ({ userId, friendId }) => {
        const me = await User.findById(userId)
        return me.findFriendById(friendId)
      }
    }
  }
}

sutro-client Output

import client from 'sutro-client'

const api = client(server.meta)

/*
All functions return promises:

api.user.create()
api.user.find()
api.user.findById()
api.user.updateById()
api.user.replaceById()
api.user.deleteById()
api.user.friend.create()
api.user.friend.find()
api.user.friend.findById()
*/

Index

Properties

Functions

Properties

combineUrl

combineUrl: (endpoint: string, query: {}) => string

Type declaration

    • (endpoint: string, query: {}): string
    • Parameters

      • endpoint: string
      • query: {}
        • [key: string]: any

      Returns string

Functions

Const default

  • default(obj: ServerMeta, globalOptions: RequestOptions): Resources
  • Parameters

    • obj: ServerMeta
    • globalOptions: RequestOptions

    Returns Resources

Legend

Generated using TypeDoc