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

@feathers-nuxt/feathers-rest-proxy

v1.0.1-beta.2

Published

A feathers service to provide real-time proxy to a REST API endpoint

Downloads

2

Readme

feathers-rest-proxy service

Feathers service for storing and retrieving data from remote REST API endpoints. This service allows the use of feathers as a proxy to access existing API endpoinds or other external systems.

Usage

Code snippets below are in livescript but its just fancy javascript.

In your service declaration file

endpoint = 
proxyService = require 'feathers-rest-proxy'
options =
  baseURL: 'https://jsonplaceholder.typicode.com'
  resourceURL: 'users'
  timeout: 5000  
  requestOkInterceptor: (config) ->
    console.log 'requestOkInterceptor request'
    # Do something with response data and resolve promise
    return config
  requestErrorInterceptor: (error) ->
    console.log 'requestErrorInterceptor error', error
    # Do something with response error and reject promise
    return Promise.reject error
  responseOkInterceptor: (response) ->
    # For response schema See https://github.com/axios/axios#response-schema
    {data, config} = response
    # Format remote API server response to match feathers service response
    console.log 'responseOkInterceptor response', response
  responseErrorInterceptor: (error) ->
    console.log 'responseErrorInterceptor error', error
    return Promise.reject error
app.use '/proxymessages', proxyService options

Note that options above is an object and baseURL is the only mandatory key. See below for other configuration options.

Configuration options

The configuration object provided to the service is passed directly to axios which is used under the hood to make HTTP requests to the remote API server from Node. baseURL is the only required parameter.

See axios configuration options for a comprehensive list of available parameters.

Creating Resources

Invoking service.create sends a HTTP POST Request to baseURL. Either JSON or FormData Object MUST be provided as the first parameter to service.create. An optional object with extra axios config options MAY be provided as the second parameter to service.create. Pass in a JSON Object to service.create will send a POST request to baseURL with the Object in the request body.

notification = 
  message: 'This is a notification message'
  sendTime: '2018-06-19 13:00:00'
  expiryTime: '2018-06-20 13:00:00' 
proxymessage = await @app.services.proxymessages.create notification

On the browser, service.create works best with JSON paylods.

Content-Type

JSON payloads will automatically be formated to a url-encoded string using querystring and sent with the request header content type set to application/x-www-form-urlencoded. While this will suffice for most cases, your API may require a different Content-Type. Simply set params.query.contentType to "multipart/form-data" and pass params as second argument to service.create. This will set the request header as specified and envelop the JSON payload in a FormData Object to send to the endpoint.

File Uploads

To send files as part of the payload, you may either send Blobs within a JSON payload or pass a FormData Object as the payload to service.create. Ensure you set the contentType to "multipart/form-data", otherwise the default content type will be used and the files will NOT be uploaded to the remote API.

On the browser, only JSON payloads will work, therefore, Files should be included in the JSON payload. Below, we are reading a HTML file input for the File using JQuery, but you may use the FileReader API of whatever else you prefer that retrieves an instance of File.

json = 
  fileName: $("#fileInput")[0].files[0]
proxyupload = await @app.services.proxyuploads.create json

On the server, you have the option of passing in an instance of FormData. Since FormData Object is not availabe on node, you have to require form-data. The same module is used under the hood when payload is JSON and params.query.contentType is set to "multipart/form-data".

# Using `form-data` npm package
FormData = require 'form-data'

# See https://github.com/form-data/form-data#alternative-submission-methods
meta =
  filename: 'unicycle.jpg'
  contentType: 'image/jpeg'
  knownLength: 19806

form = new FormData
form.append 'fileName', (require 'fs').createReadStream('file.ext'), meta
proxyupload = await @app.services.proxyuploads.create form, params # Ensure you pass along params

While converting JSON to FormData, form.append is called with two parameters unlike above. You may include file metadata in the JSON payload under the key meta as an object whose keys are filenames and values are similar to fileMeta above. This will call form.append with three parameters as above.

See https://gist.github.com/joyrexus/524c7e811e4abf9afe56