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

@ephox/jax

v7.0.10

Published

AJAX library

Downloads

7,579

Readme

Description

jax is a library for handling AJAX requests and responses. It does not bundle any commands. It is only a collection of modules.

Installation

jax is available as an npm package. You can install it via the npm package @ephox/jax

Install from npm

npm install @ephox/jax.

Using the API

jax supports several methods, content types, and response types. More specifically,

Methods: GET, POST, PUT, DELETE Content Types: none, form, json, plain, html Response Types: json, blob, text, html, xml

In addition, credentials can be sent with the request. More information can be found here.

The ephox.jax.api.Ajax APIs provide the various methods for making AJAX requests. They all return a LazyValue (see katamari) which is a promise-like data structure with get, map, and isReady functions. The APIs also take an additional parameter at the end for any custom request headers, which defaults to {} if it is not provided.

ContentType, ResponseType, and Credentials are specified using the constructors inside ephox.jax.api.ContentType, ephox.jax.api.ResponseType, and ephox.jax.api.Credentials respectively.

GET Requests

Ajax.get(url, responseType, credentials, _custom)

This fires a GET request with the specified response type. The content type is sent as none.

Ajax.get(
  'http://localhost/server/get/1',
  ResponseType.json(),
  Credentials.none(),
  { }
).get(function (result) {
  // result is a result, so you need to fold over it for Err or Succ(x)
  result.fold(function (err) {
    console.error('Server error', err);
  }, function (val) {
    console.log('Get response', val);
  })
});

POST Requests

Ajax.post(url, contentType, responseType, credentials, _custom)

This fires a POST request with the specified response type and content type.

Ajax.post(
  'http://localhost/server/post',
  ContentType.json({
    'send-data': '10'
  }),
  ResponseType.xml(),
  Credentials.none(),
  { }
)).get(function (result) {
  // result is a result, so you need to fold over it for Err or Succ(x)
  result.fold(function (err) {
    console.error('Server error', err);
  }, function (xml) {
    console.log('Post response', xml);
  })
});

PUT Requests

Ajax.put(url, contentType, responseType, credentials, _custom)

This fires a PUT request with the specified response type and content type.

Ajax.put(
  'http://localhost/server/put',
  ContentType.json({
    'send-data': '10'
  }),
  ResponseType.json(),
  Credentials.none(),
  { }
)).get(function (result) {
  // result is a result, so you need to fold over it for Err or Succ(x)
  result.fold(function (err) {
    console.error('Server error', err);
  }, function (val) {
    console.log('Put response', val);
  })
});

DELETE requests

Ajax.del(url, responseType, credentials, _custom)

This fires a DELETE request with the specified response type.

Ajax.get(
  'http://localhost/server/del/1',
  ResponseType.json(),
  Credentials.none(),
  { }
).get(function (result) {
  // result is a result, so you need to fold over it for Err or Succ(x)
  result.fold(function (err) {
    console.error('Server error', err);
  }, function (val) {
    console.log('Delete response', val);
  })
});

Running Tests

$ yarn test

These tests require bedrock and chrome.