Socket
Socket
Sign inDemoInstall

rails-fetch

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rails-fetch

A tiny Fetch API wrapper that allows you to make http requests without need to handle to send the CSRF Token on every request


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Rails Fetch

Rails Fetch encapsulates the logic to send by default some headers that are required by rails applications like the X-CSRF-Token.

Install

npm

npm i rails-fetch

yarn

yarn add rails-fetch

How to use

Just import the Request class from the package and instantiate it passing the request method, url, options, then call await request.perform() and do what do you need with the response.

Example:

import { Request } from 'rails-fetch'

....

async myMethod () {
  const request = new Request('post', 'localhost:3000/my_endpoint', { body: { name: 'Rails Fetch' }})
  const response = await request.perform()
  if (response.ok) {
    const body = await response.text
    // Do whatever do you want with the response body
    // You also are able to call `response.html` or `response.json`, be aware that if you call `response.json` and the response contentType isn't `application/json` there will be raised an error.
  }
}

Credits

Basecamp, since this piece of code has been extracted from hey.com.

License

Rails Fetch is released under the MIT License.

Keywords

FAQs

Last updated on 02 Jun 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc