Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metal-ajax

Package Overview
Dependencies
Maintainers
10
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metal-ajax

Metal.js utility to perform Ajax requests

  • 3.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by182.02%
Maintainers
10
Weekly downloads
 
Created
Source

metal-ajax

Build Status

Build Status

Low-level Metal.js utility to perform Ajax requests. If you're looking for something higher level, take a look at fetch.

Use

Simple request

import Ajax from 'metal-ajax';

Ajax.request('/url', 'get')
  .then(xhrResponse => {
    // Handle response
  });

Posts

Ajax.request('/url', 'post', 'requestBody')
  .then(xhrResponse => {
    // Handle response
  });

Request headers and params

Custom request headers and params can bet set using a MultiMap from metal-structs.

import {MultiMap} from 'metal-structs';

const headers = new MultiMap();
const params = new MultiMap();

headers.add('content-type', 'application/json');
params.add('foo', 'bar');

Ajax.request('/url', 'get', null, headers, params)
  .then(function(xhrResponse) {
    // Handle response
  });

Catching errors

Ajax.request('/url', 'get')
  .then(xhrResponse => {
    // Handle response
  })
  .catch(error => {
    // Handle error
  });

Watch for progress

In order for the progress listener to work, the response must have the Content-Length response header set.

Ajax.request('/url', 'get')
  .progress(progress => {
    // Fires with a value between 0 and 1 representing the percent
  })
  .then(xhrResponse => {
    // Handle response
  })

Setup

  1. Install a recent release of NodeJS if you don't have it yet.

  2. Install local dependencies:

npm install
  1. Run the tests:
npm test

Contributing

Check out the contributing guidelines for more information.

Keywords

FAQs

Package last updated on 20 Feb 2018

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc