Skip to content

Commit

Permalink
add header, reduce size, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzarghili committed Mar 2, 2019
1 parent cee8cf8 commit 6890df1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

Minimalistic xhr javascript library `experimental`

**603B** minified version
**587B** minified version

## Usage

The best optimal approach is to add the minified inline to avoid extra http calls
The best optimal approach is to add the minified version inline to avoid extra http calls

```html
<script>
((e,t,r)=>{e.xorq={},t=((t,o,s,a)=>((s=new XMLHttpRequest).open(o,t,!0),(r=e.xorq.timeout)&&(s.timeout=r),s.onreadystatechange=s.then=((e,t,r,o,n)=>{if(e&&e instanceof Function&&(a=[,e,t]),a&&4==s.readyState){if(r=a[0|s.status/200]){n=s.responseText;try{o=JSON.parse(n)}catch(e){o=n}return void r(o,s)}a[2]&&a[2]({error:"net/timout... error"},s)}}),s)),methods=["GET","POST","PUT","PATCH","DELETE"],methods.map(r=>{e.xorq[r.toLowerCase()]=((o,s,a={},n=e.xorq.headers)=>(xhr=t(o,r),n||(n={}),a=Object.assign({},n,a),Object.keys(a).forEach(e=>{xhr.setRequestHeader(e,a[e])}),xhr.send(s),xhr))})})(window);
((e,t,r)=>{e.xorq={},t=((t,o,s,a)=>((s=new XMLHttpRequest).open(o,t,!0),(r=e.xorq.timeout)&&(s.timeout=r),s.onreadystatechange=s.then=((e,t,r,o,n)=>{if(e&&e instanceof Function&&(a=[,e,t]),a&&4==s.readyState){if(r=a[0|s.status/2e2]){n=s.responseText;try{o=JSON.parse(n)}catch(e){o=n}return void r(o,s)}a[2]&&a[2]({error:"net/timout... error"},s)}}),s)),["HEAD","GET","POST","PUT","PATCH","DELETE"].map(r=>{e.xorq[r.toLowerCase()]=((o,s,a={},n=e.xorq.headers,i)=>(i=t(o,r),n||(n={}),a=Object.assign({},n,a),Object.keys(a).forEach(e=>{i.setRequestHeader(e,a[e])}),i.send(s),i))})})(window)
</script>
```

Or you can use the dist file

```html
<script src="https://github.com/ezzarghili/xorq/releases/download/v1.1.0/xorq.min.js">
<script src="https://github.com/ezzarghili/xorq/releases/download/v1.1.1/xorq.min.js">
</script>
```

You can use the code this way

```javascript
// available methods GET, POST, PUT, PATCH, DELETE
// available methods HEAD, GET, POST, PUT, PATCH, DELETE
// get resource
xorq.get("http://example.com")
.then(
Expand Down
2 changes: 1 addition & 1 deletion dist/xorq.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/xorq.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ SOFTWARE.*/
}
return xhr
}
methods = ['GET', "POST", "PUT", "PATCH", "DELETE"];
methods.map(method => {
window.xorq[method.toLowerCase()] = (url, data, headers = {}, xh = window.xorq.headers) => {
['HEAD', 'GET', "POST", "PUT", "PATCH", "DELETE"].map(method => {
window.xorq[method.toLowerCase()] = (url, data, headers = {}, xh = window.xorq.headers, xhr) => {
xhr = _prep(url, method);
xh || (xh = {})
headers = Object.assign({}, xh, headers);
Expand Down

0 comments on commit 6890df1

Please sign in to comment.