1.0.0 • Published 6 years ago

axios-restful v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

axios-restful

Integration

This code is designed to work with axios configurations. Axios will be imported automatically and does not need extra imports within your project.

Methods

#constructor(options = {})

The constructor takes a set of arguments. The following options can be specified:

ParameterTypeRequiredDefault Value
headersJSON Objectno{ 'Accept': 'application/json', 'Content-Type': 'application/json' }
requestInterceptorsArray of Functionsno[]
responseTransformationsArray of Functionsno[]
retriesNumberno1
updateTypeStringno'PUT'
sslBooleannofalse
domainStringno'localhost'

Note that some configurations are suggested, such as ssl and domain for full functionality beyond testing locally.

#addResource(resourceName, namespace = undefined)

This method adds the following routes for a specified resource:

FunctionTypeEndpoint
allGET/
findGET/:id
updatePUT/PATCH/:id
createPOST/
deleteDELETE/:id

These functions will be added to the specified namespace if provided. The namespace uses Lodash style dot notation to specify the nesting. An example of this would be foo.bar would create the above methods in { "foo": { "bar": {...} } }.

#addRoute(type, name, endpoint = undefined, namespace = undefined)

This method will generate an endpoint within a specified namespace.

ParameterRequiredDefault Behaviour
typeyesSpecifies the type of request
nameyesSpecifies the name of the resource
endpointnoIf the endpoint is not specified it will use the name as the endpoint
namespacenoIf the namespace is not provided it will be added at the root level

#axios()

Returns axios as used by this package.

#routes()

Returns a JSON Object with functions for each of the routes. The routes would be specified by #addResource and #addRoute.