UNPKG

@hookcompany/feathers-client-custom-methods

Version:

️🏹 Create feathers service on client with custom methods names.

116 lines (73 loc) 2.53 kB
# Feathers Client Custom Methods ## 🏹 Create feathers service on client with custom methods names. [![NPM version](https://badge.fury.io/js/%40hookcompany%2Ffeathers-client-custom-methods.png)](http://badge.fury.io/js/%40hookcompany%2Ffeathers-client-custom-methods) [![Npm Downloads](https://nodei.co/npm/@hookcompany%2Ffeathers-client-custom-methods.png?downloads=true)](https://nodei.co/npm/@hookcompany%2Ffeathers-client-custom-methods.png?downloads=true) ## Getting Started Use npm: ```sh npm install --save @hookcompany/feathers-client-custom-methods ``` Or use yarn: ```sh yarn add @hookcompany/feathers-client-custom-methods ``` ## Prerequisite Install @hookcompany/feathers-custom-methods on server ([Fathers Custom Methods](https://www.npmjs.com/package/@hookcompany/feathers-custom-methods)) ## Config #### Bootstrap ```javascript import feathers from '@feathersjs/feathers'; import feathersRestClient from '@feathersjs/rest-client'; import axios from 'axios'; import feathersCustomMethods from '@hookcompany/feathers-client-custom-methods'; const HTTP_URI = '<endPoint>'; const rest = feathers() .configure(feathersRestClient(HTTP_URI).axios(axios)); feathersCustomMethods.bootstrap(rest) .then(Feathers => { const Feeds = Feathers.service('feeds'); Feeds.foo() .then(console.log) .catch(console.log); }); ``` #### or #### Options ```javascript import feathers from '@feathersjs/feathers'; import feathersRestClient from '@feathersjs/rest-client'; import axios from 'axios'; import feathersCustomMethods from '@hookcompany/feathers-client-custom-methods'; const HTTP_URI = '<endPoint>'; const rest = feathers() .configure(feathersRestClient(HTTP_URI).axios(axios)) .configure(feathersCustomMethods()); const Feeds = rest.service('feeds', [ 'foo:find', 'bar:find', 'buzz:get', 'foobar:create', 'foobuzz:update', 'barbuzz:patch', 'foobarbuzz:remove' ]); Feeds.foo() .then(console.log) .catch(console.log); ``` ## Consuming The Service Methods You can consume the service methods, like that: #### Method foo(find) [GET] localhost:3030/users/foo #### Method bar(find) [GET] localhost:3030/users/bar #### Method buzz(get) [GET] localhost:3030/users/buzz/:id #### Method foobar(create) [POST] localhost:3030/users/foobar #### Method foobuzz(update) [PUT] localhost:3030/users/foobuzz/:id #### Method barbuzz(patch) [PATCH] localhost:3030/users/barbuzz/:id #### Method foobarbuzz(remove) [DELETE] localhost:3030/users/foobarbuzz/:id