Icontem

JS Rest Client: Send HTTP REST API requests using XMLHttpRequest

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2014-10-14 (5 years ago) RSS 2.0 feedNot enough user ratingsTotal: 184 All time: 274 This week: 3Up
Version License JavaScript version Categories
js-rest-client 1.0.3MIT/X Consortium ...1.0AJAX, Web services
Description Author

This object send HTTP REST API requests using XMLHttpRequest.

It can send HTTP GET, POST, PUT, DELETE, PATCH, OPTIONS and HEAD requests to a given REST API URL using AJAX requests.

The object can take options for all types of request that may define additional parameters for defining things like for instance taking FormData objects to send form requests.

Special callback parameters may be specified to tell the object to call given functions in case the HTTP request succeeded or failed in error.

Name: Elger van Boxtel <contact>
Classes: 4 packages by
Country: The Netherlands The Netherlands
Age: ???
All time rank: 292 in The Netherlands The Netherlands
Week rank: 24 Up1 in The Netherlands The Netherlands Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Details

JSRest

Javascript REST API to communicate with the backend

Fork me on GitHub https://github.com/elgervb/JSRest

Usage

// create your new rest object to version v1.0
var rest = new Rest("http://your.server.com/v1.0/base");

// perform get request to http://your.server.com/base/object
rest.get('/object')

// add a new object
rest.post('/object', {data: {prop: 'value', prop2: 'value2'}});

// get a new object with success / failure callbacks
var options = {
	data: {prop: 'value', prop2: 'value2'},
	success: function(data, status, xhr){
		document.getElementById('result').innerHTML = data;
	},
	error: function(error, errorType, xhr){
		document.getElementById('error').innerHTML = 'Failed to retrieve object. Error: ' + error;
	}
};
rest.get('/object/32', options)

Request Types

The Rest library supplies a number of default requests:

  • GET : Rest.get Get (a list of) resources
  • POST : Rest.post Add a new resource
  • PUT : Rest.put Change a resource
  • PATCH : Rest.patch Change a part of a resource
  • DELETE : Rest.delete Delete a resource
  • OPTIONS : Rest.options Request the capablities of the requested url
  • HEAD : Rest.head Check is the resource exists

Apart from those, you can always create your own with the request method, just supply the options.type option.

Request Options

| Key | Type | Default | Description | |-------------|---------------|:--------------------------------:|--------------------------------| | url | string | | The request url. If you're set the baseurl on the Rest object then the url will be appended | | headers | object |{} | Any additional headers to supply to the backend | | xhrFields | object | {withCredentials: false} | Any additional field to extend the XmlHttpRequest with | | debug | boolean | false | Whether to run in debug mode for additional console logging | | type | string | GET | The request type. Only set this when using the request method | | success | function | | Callback to be executed on success | | error | function | | Callback to be executed on failure | | data | object | | data to be supplies when making the request |

  Files folder image Files  
File Role Description
Files folder imagelib (1 file)
Files folder imagetests (1 file, 2 directories)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  lib  
File Role Description
  Plain text file Rest.js Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagelib (1 directory)
Files folder imagespec (1 file)
  Accessible without login Plain text file SpecRunner.html Aux. Sample output

  Files folder image Files  /  tests  /  lib  
File Role Description
Files folder imagejasmine-2.0.2 (6 files)

  Files folder image Files  /  tests  /  lib  /  jasmine-2.0.2  
File Role Description
  Accessible without login Plain text file boot.js Test Unit test script
  Accessible without login Plain text file console.js Test Unit test script
  Accessible without login Plain text file jasmine-html.js Test Unit test script
  Accessible without login Plain text file jasmine.css Output Sample output
  Accessible without login Plain text file jasmine.js Test Unit test script
  Accessible without login Image file jasmine_favicon.png Icon Icon image

  Files folder image Files  /  tests  /  spec  
File Role Description
  Accessible without login Plain text file RestSpec.js Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:184
This week:0
All time:274
This week:3Up