New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

restfulpy

Package Overview
Dependencies
Maintainers
4
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restfulpy

A javascript client for restfulpy

latest
Source
npmnpm
Version
0.22.7
Version published
Maintainers
4
Created
Source

restfulpy-client.js

Javascript client for restfulpy

NPM Build Status Coverage Status License

Install

npm install restfulpy
sudo apt-get install redis-server

Create a postgres database named: restfulpymockupserver

Usage

import { BrowserSession, Authenticator, httpClient, Response } from 'restfulpy'

class LocalAuthenticator extends Authenticator {
  login(credentials) {
    // Add your login method for example:
    return httpClient(
      `http://example.org/api/v1/sessions`,
      {
        verb: 'POST',
        payload: this.constructor.validateCredentials(credentials)
      },
      (...args) => {
        return new Response(null, ...args)
      }
    )
      .then(resp => {
        this.token = resp.json.token
        return Promise.resolve(resp)
      })
      .catch(resp => {
        this.deleteToken()
        return Promise.reject(resp)
      })
  }
}

let authenticator = new LocalAuthenticator()

const errorHandler = {
  401: (status, redirectUrl) => {
    // Your handler for 401 error
    // You can add handler for each status code
  }
}

let client = new BrowserSession(
  'http://example.org/api/v1',
  undefined,
  authenticator,
  errorHandlers
)

// Login
client
  .login({ email: 'user1@example.com', password: '123456' })
  .then(resp => {
    // Authentication success, so
    console.log(resp.json.token) // is not null
    console.log(client.authenticator.authenticated) // is true
  })
  .catch(resp => {
    throw resp.error
  })

// Posting some data to `http://example.org/api/v1/echo`
client
  .request('echo', 'POST')
  .addParameters({ item1: 'Value1' })
  .send()
  .then(resp => {
    console.log(resp.status) // Is 200
    console.log(resp.json)
    console.log(resp.getHeader('Content-Type'))
  })
  .catch(resp => {
    console.log(resp.status)
    throw resp.error
  })

// Logout
client.logout()

Metadata


client.metadata.ModelName.get(1).done(models => {
  // Use model
})

client.metadata.ModelName.load().done(models => {
  // Use models
})

Development Environment Setup

git clone <repo> && cd into/cloned/repo
npm install
sudo apt-get install redis-server

Build

npm run build

Running tests

An instance of the restfulpy is required as a mock-up server before running tests, see the mockup-server-karma.py and tests directory to understand why you need to setup a python virtual env to run tests.

Adding some stuff into the ~/.bashrc file.

alias v.activate="source /usr/local/bin/virtualenvwrapper.sh"
export VIRTUALENVWRAPPER_PYTHON="$(which python3.6)"

Re-source the ~/.bashrc

source ~/.bashrc

Sourcing the virtualenv wrapper.

v.activate

Creating a dedicated virtualenv for this project.

mkvirtualenv --python=$(which python3.6) restfulpy

Installing the python dependencies

pip install "restfulpy >= 1.1.2a1"

Finally! Running the tests.

npm run test

Or,

npm run test -- --no-single-run

To keep the browser open for more investigation and watch for changes. see karma documents for more info.

Browser Support

FirefoxChromeIE/EdgeSafariOpera
174112.0928

FAQs

Package last updated on 07 Jun 2020

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