All Projects → sumeetsarkar → solarjs

sumeetsarkar / solarjs

Licence: MIT License
Solar is a fast, small, and highly configurable JavaScript XHR wrapper library.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to solarjs

Frisbee
🐕 Modern fetch-based alternative to axios/superagent/request. Great for React Native.
Stars: ✭ 1,038 (+6820%)
Mutual labels:  xhr
Breep
C++ peer to peer library, built on the top of boost
Stars: ✭ 111 (+640%)
Mutual labels:  network-library
http
Tiny, embeddable HTTP client with simple API for the browser
Stars: ✭ 21 (+40%)
Mutual labels:  xhr
Mithril.js
A JavaScript Framework for Building Brilliant Applications
Stars: ✭ 13,062 (+86980%)
Mutual labels:  xhr
Pending Xhr Puppeteer
Small tool to wait that all xhr are finished in puppeteer
Stars: ✭ 227 (+1413.33%)
Mutual labels:  xhr
upload-file-to-backblaze-b2-from-browser-example
Demonstrates calling the b2_upload_file Backblaze B2 Cloud Storage API from a web browser using AJAX.
Stars: ✭ 28 (+86.67%)
Mutual labels:  xhr
Xhr.js
🌎 xhr.js is a library(< 2Kb) to make AJAX/HTTP requests with XMLHttpRequest.
Stars: ✭ 12 (-20%)
Mutual labels:  xhr
sapper-httpclient
An isomorphic http client for Sapper
Stars: ✭ 48 (+220%)
Mutual labels:  xhr
I18next Xhr Backend
[deprecated] can be replaced with i18next-http-backend
Stars: ✭ 252 (+1580%)
Mutual labels:  xhr
i18next-http-backend
i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
Stars: ✭ 270 (+1700%)
Mutual labels:  xhr
Xhr Mock
Utility for mocking XMLHttpRequest.
Stars: ✭ 188 (+1153.33%)
Mutual labels:  xhr
Axios Tutorial
axios实例应用及源码剖析 - xhr篇 (走心教程)
Stars: ✭ 219 (+1360%)
Mutual labels:  xhr
SimEthereal
A high performance library for real-time networked object synching.
Stars: ✭ 24 (+60%)
Mutual labels:  network-library
Interceptors
Low-level HTTP/HTTPS/XHR/fetch request interception library.
Stars: ✭ 100 (+566.67%)
Mutual labels:  xhr
angular-progress-http
[DEPRECATED] Use @angular/common/http instead
Stars: ✭ 43 (+186.67%)
Mutual labels:  xhr
Rext
🎈A lightweight (< 5kb gzipped) and Promise-supported HTTP request library, for all browsers.
Stars: ✭ 14 (-6.67%)
Mutual labels:  xhr
rxhr
Tiny Observable based HTTP client for browsers
Stars: ✭ 15 (+0%)
Mutual labels:  xhr
cypress-xhr-responses-recording
No description or website provided.
Stars: ✭ 19 (+26.67%)
Mutual labels:  xhr
speedtest
A self-hosted, lightweight HTML5 speed test implemented in JavaScript, based on Web Workers and XMLHttpRequest.
Stars: ✭ 154 (+926.67%)
Mutual labels:  xhr
Android-Web-Inspector
How to Inspecting Android WebView, Network logs, XHR logs (including url request and parameter) and Element/DOM inspecting
Stars: ✭ 54 (+260%)
Mutual labels:  xhr

Solar

Solar is a fast, small, and highly configurable JavaScript XHR wrapper library.

The main Idea is to have Request groups defined. So what are request groups? - Request groups are bundles of API endpoints which can define common basePaths, headers, responseTypes etc and other configs necessary under a group. A single API endpoint declares its method type, relative Url (bare minimum) and in addition specific headers or responseType, configs to override parent.

Key Features:

  1. By default provides two request groups - Auth and UnAuth
  2. Custom Request Groups to group APIs under group names to define group configs
  3. Custom Request Groups can inherit optionally from parent groups
  4. JSON based Config declaration or specific setup with method chaining

Once the configuration is done, Solar can be used to make XHR requests with just the api name or group name if any. If needed additional parameter payload can be passed in as argument apart from the regular success and error callbacks.

However, Solar can also be used to send XHR requests wihtout any configs for standalone requests.

Limitations for now

Currently supports GET, POST, PUT

Upcoming features

  1. Promises support
  2. HTTP Delete support

Including Solar

Solar is available only as standalone library from github repo. No CDN support as of now.

Browser

Script tag

<script src="<your-path>/solar.min.js"></script>

How To Use Solar

Chain addition of solar config

$olar.setBaseUrl(baseUrl)
    .setAuthenticatedEndpoints(authEndpoints)
    .setUnAuthenticatedEndpoints(unAuthEndpoints)
    .setCommonHeaders(commonHeaders)
    .setAuthConfig(authConfig)
    .setUnAuthConfig(unAuthConfig)
    .addCustomRequestGroup('group1', group1)
    .addCustomRequestGroup('group2', group2)
    .addCustomRequestGroup('group3', group3);

Or Load full config at once from json

$olar.loadConfig(solarConfig);

Solar config declaration styles

  1. Individual Config
  2. Single JSON config

Solar example usage

Example usage in app.js

Simple Solar call once config is done

$olar.executeAuth('profile');
$olar.executeUnAuth('status');
$olar.executeCustom('group1', 'status');

Making Authenticated API requests

As per configuration, Solar picks up the following - Http Method type, Auth specific/ common/ endpoint specific headers, Auth basePath, XHR Reponse Type. Additional headers can be passed on while sending the request. Function executeAuth takes in payload, success callback and error callback

$olar.executeAuth('profile-update',
    {   
        data: { /* Post Data */
            name: ['Sumeet Sarkar']
        },
        headers: { /* Headers */
            'X-Auth-Dynamic': 'some-dynamic-data'
        }
    },
    (data) => /* Success callback */ console.log(data),
    (err) => /* Error callback */ console.error(err)
);

Making Unauthenticated API requests

As per configuration, Solar picks up the following - Http Method type, Common/ endpoint specific headers, UnAuth basePath, XHR Reponse Type. Additional headers can be passed on while sending the request. Function executeUnAuth takes in payload, success callback and error callback

$olar.executeUnAuth('echo', 
    {   
        params: { /* Query Params */
            version: 1234,
            locale: 'en'
        }
    },
    (data) => /* Success callback */ console.log(data),
    (err) => /* Error callback */ console.error(err)
);

Making Custom Group API requests

Solar picks up the api from the group specified and merges group specific & common configs together. If the custom group inherits a parent group like auth or unauth, then corresponding parent's configs are merged.

// call custom group api
$olar.executeCustom('group1', 'status', 
    {}, /* No Post Data */ /* No Query params */
    (data) => /* Success callback */ console.log(data),
    (err) => /* Error callback */ console.error(err)
);

Bypassing all configs and using Solar to make simple standalone XHR

$olar.request({
        /* Method */
        method: 'GET',
        /* Url */
        url: '/api/app/echo?version={version}&locale={locale}',
        /* Query Params */
        params: { 
            version: 1234,
            locale: 'en'
        },
        /* Headers */
        headers: {
            'X-App-Name': 'Demo $olar',
            'X-App-Key' : 'myappkey',
            'Content-Type': 'application/json'
        }
    },
    (data) => /* Success callback */ console.log(data),
    (err) => /* Error callback */ console.error(err)
);

To display all configs

$olar.info();

Starting the example

npm run start-example

Build Solar dist

npm run build
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].