7.0.10 • Published 3 months ago

@ephox/jax v7.0.10

Weekly downloads
1,495
License
MIT
Repository
github
Last release
3 months ago

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.

7.0.10

3 months ago

7.0.9

1 year ago

7.0.7

1 year ago

7.0.5

2 years ago

7.0.2-alpha.1

2 years ago

7.0.3

2 years ago

7.0.2-alpha.0

2 years ago

7.0.0-alpha.3

2 years ago

7.0.0-alpha.2

2 years ago

7.0.0-alpha.4

2 years ago

7.0.0

2 years ago

7.0.1

2 years ago

7.0.0-alpha.1

2 years ago

7.0.0-alpha.0

2 years ago

6.0.3

3 years ago

6.0.1

3 years ago

5.0.7

3 years ago

5.0.5

3 years ago

5.0.3

3 years ago

5.0.1

4 years ago

4.1.36

4 years ago

4.1.35

4 years ago

4.1.33

4 years ago

4.1.31

4 years ago

4.1.30

4 years ago

4.1.28

5 years ago

4.1.26

5 years ago

4.1.25

5 years ago

4.1.24

5 years ago

4.1.22

5 years ago

4.1.20

5 years ago

4.1.19

5 years ago

4.1.18

5 years ago

4.1.16

5 years ago

4.1.15

5 years ago

4.1.14

5 years ago

4.1.13

5 years ago

4.1.12

5 years ago

4.1.11

5 years ago

4.1.10

5 years ago

4.1.9

5 years ago

4.1.8

5 years ago

4.1.6

5 years ago

4.1.5

5 years ago

4.1.4

5 years ago

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.0.1

5 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.0.10

6 years ago

3.0.9

6 years ago

3.0.8

6 years ago

3.0.7

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

2.2.0

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago