npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

restfulpy

v0.22.7

Published

A javascript client for restfulpy

Downloads

99

Readme

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: '[email protected]', 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

| Firefox | Chrome | IE/Edge | Safari | Opera | | ---------- | --------- | ---------- | --------- | -------- | | 17 | 41 | 12.0 | 9 | 28 |