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

batchcall

v1.6.2

Published

batchcall.js is small useful helper extended from jQuery ajax() to use for requesting batch call

Downloads

4

Readme

Batchcall.js

Batchcall.js is an extension of jQuery ajax function that make sending batch requests to the desire server super easy, just fill the parameters and data and it's done, leave the heavy lifting of on Batchcall.js to work for your batch request.

What is batch request

Batch requests allow grouping multiple operations, as described in [OData:Core], into a single HTTP request payload. A batch request MUST be represented as a Multipart MIME v1.0 message [RFC2046], a standard format allowing the representation of multiple parts, each of which may have a different content type (as described in [OData:Atom], [OData:JSON] and [OData:JSONVerbose]), within a single request. This feature allows you to decrease the traffic between the server and the client dramatically making the entire communication much less "chatty" (and therefore, making your API more scalable).

Batch Request Headers

Batch requests MUST be submitted as a single HTTP POST request to the batch endpoint of a service, which MUST be located at the URI /$batch. Service Root URIs are defined in [OData:Core].

The batch request MUST contain a Content-Type header specifying a content type of “multipart/mixed” and a boundary specification as defined in [RFC2046]. is defined in the Batch Request Body section below.

    POST /service/$batch HTTP/1.1
    Host: odata.org
    DataServiceVersion: 1.0 
    MaxDataServiceVersion: 3.0 
    Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b

<--Batch Request Body-->

Finally, batch requests MUST NOT include an X-HTTP-Method header (i.e. use POST tunelling) as batch requests are by definition POST only.

Batch Request Body

The body of a batch request MUST be made up of an ordered series of query operations and/or ChangeSets. A query operation in the context of a batch request is either a query or Function invocation request as described in [OData:Core]. A ChangeSet is an atomic unit of work consisting of an unordered group of one or more of the insert/update/delete operations, Action invocations or Service Operation invocations described in [OData:Core]. ChangeSets MUST NOT contain query operations and MUST NOT be nested (i.e. a ChangeSet cannot contain a ChangeSet).

POST /service/$batch HTTP/1.1 
Host: host 
Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b 

--batch_36522ad7-fc75-4b56-8c71-56071383e77b
Content-Type: application/http 
Content-Transfer-Encoding:binary

GET /service/Customers('ALFKI') 
Host: host

--batch_36522ad7-fc75-4b56-8c71-56071383e77b 
Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 
Content-Length: ###       

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 
Content-Type: application/http 
Content-Transfer-Encoding:binary 

PUT /service/Customers('ALFKI') HTTP/1.1 
Host: host 
Content-Type: application/json 
If-Match: xxxxx 
Content-Length: ### 

<JSON representation of Customer ALFKI> 

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621-- 

--batch_36522ad7-fc75-4b56-8c71-56071383e77b--

Further learning about Batch Request [OData Version 3.0 documentation]

http://www.odata.org/documentation/odata-version-3-0/batch-processing/

Using the code

The batching support is implemented via oDataBatchAjaxCall method which can be called on a global jQuery object. The semantics of oDataBatchAjaxCall method are more or less the same as with the native ajax method.

Below is an example of performing a batch request to a handler available at /api/batch:


 var requestParams = [];
 requestParams.push({
	'requestType'    : 'PUT', //method type
    	'crudWhereClause': '/service/Customers('ALFKI')', //CRUD Where clause
    	'data'           : modelData //JSON properly formatted data, could be collection
                });
                
                
$.oDataBatchAjaxCall(requestParams);

//To use with Promise to handle any callback
var batchCallPromise = $.oDataBatchAjaxCall(requestParams);
batchCallPromise.done(function () {
    myCallBack(); //Your Callback function
});

Dependencies

Batch.js depends on jQuery >= 1.5.x (although, this dependency can easily be eliminated). The library also takes advantage of the native JSON library (e.g. parse and stringify methods). Please refer to https://github.com/douglascrockford/JSON-js if you're targeting browsers that don't support JSON object natively.

Support

Currently batchcall.js only supports application/json as content type (and therefore, enforces it when sending the request and receiving the response).