All Projects → jvanbruegge → minireq

jvanbruegge / minireq

Licence: other
A minimal request library for the browser

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to minireq

heroshi
Heroshi – open source web crawler.
Stars: ✭ 51 (+21.43%)
Mutual labels:  http-client
lhc
🚀 Advanced HTTP Client for Ruby. Fueled with interceptors.
Stars: ✭ 32 (-23.81%)
Mutual labels:  http-client
http-interceptors
The Web apps in this monorepo make HTTP requests and require uniform consistency in how they are executed and handled. This monorepo demonstrates the same app written with Angular and with Svelte. Each app uses HTTP interceptors. The Angular app uses HttpClient and its interceptors while the Svelte app uses Axios and its interceptors.
Stars: ✭ 46 (+9.52%)
Mutual labels:  http-client
ivar
Ivar is an adapter based HTTP client that provides the ability to build composable HTTP requests.
Stars: ✭ 14 (-66.67%)
Mutual labels:  http-client
RESTEasy
REST API calls made easier
Stars: ✭ 12 (-71.43%)
Mutual labels:  http-client
ELWebService
A lightweight HTTP networking framework for Swift
Stars: ✭ 89 (+111.9%)
Mutual labels:  http-client
foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 61 (+45.24%)
Mutual labels:  http-client
fetchx
Beautiful way to fetch data in React
Stars: ✭ 71 (+69.05%)
Mutual labels:  http-client
desktop
A native GUI application that makes it easy to explore and test Serverless Framework applications built on AWS Lambda.
Stars: ✭ 42 (+0%)
Mutual labels:  http-client
monolog-http
A collection of monolog handlers that use a PSR-18 HTTP Client to send your logs
Stars: ✭ 34 (-19.05%)
Mutual labels:  http-client
chclient
Fast http client for SELECT queries in clickhouse
Stars: ✭ 44 (+4.76%)
Mutual labels:  http-client
Rester
A command line tool to test (REST) APIs
Stars: ✭ 42 (+0%)
Mutual labels:  http-client
rq
A nicer interface for golang stdlib HTTP client
Stars: ✭ 40 (-4.76%)
Mutual labels:  http-client
centra
Core Node.js HTTP client
Stars: ✭ 52 (+23.81%)
Mutual labels:  http-client
fetch-wrap
extend WHATWG fetch wrapping it with middlewares
Stars: ✭ 21 (-50%)
Mutual labels:  http-client
libashttp
A C++ async HTTP client library to use in asynchronous applications while communicating with REST services.
Stars: ✭ 51 (+21.43%)
Mutual labels:  http-client
SimplecURL
Easy to use HTTP Client for PHP
Stars: ✭ 14 (-66.67%)
Mutual labels:  http-client
gohttp
A simple to use golang http client
Stars: ✭ 47 (+11.9%)
Mutual labels:  http-client
MultipartEncoder
C++ implementation of encoding HTTP multipart/form-data into a string buffer for POST action in HTTP clients
Stars: ✭ 45 (+7.14%)
Mutual labels:  http-client
nativescript-http
The best way to do HTTP requests in NativeScript, a drop-in replacement for the core HTTP with important improvements and additions like proper connection pooling, form data support and certificate pinning
Stars: ✭ 32 (-23.81%)
Mutual labels:  http-client

minireq

build docs codecov code style: prettier

A minimal request library built on XMLHTTPRequest for the browser, and for nodejs with the same API.

Documentation on Github Pages

Why not fetch, axios or superagent

fetch is too bare bones and also does not support features like progress indication. axios and superagent are neither minimal nor are they written with ES modules with makes them awkward to bundle.

Also I want a request library with better types than currently available.

Example

import { makeRequest } from '@minireq/browser';
// If you are using nodejs, you can use
// import { makeRequest } from '@minireq/node';

const request = makeRequest();

const { promise, abort } = request({
    method: 'GET',
    url: '/api/users',
});

// Abort on user click
document.querySelector('button.abortRequest').addEventListener('click', () => {
    abort();
});

promise.then(({ status, data }) => {
    if (status === 200) {
        console.log(data.name);
    }
});

Making a post request, with a timeout on 500ms

import { makeRequest } from '@minireq/browser';

const request = makeRequest();

const { promise } = request({
    method: 'POST',
    url: '/api/users',
    send: {
        name: 'Peter',
        age: 50,
        children: [],
    },
    timeout: 500,
});

promise.then(({ status, data }) => {
    if (status === 201) {
        console.log(data.id);
    }
});

Using a custom content type

import { makeRequest, defaultSerializers } from '@minireq/browser';

const serializer = {
    parse: (data: string) => data.split('\n').map(x => JSON.parse(x)),
    convert: (data: any) => {
        if (!Array.isArray(data)) {
            return [JSON.stringify(data)];
        } else {
            return data.map(x => JSON.stringify(x)).join('\n');
        }
    },
};

const { request } = makeRequest({
    ...defaultSerializers,
    'application/ndjson': serializer,
});

const { promise, abort } = request({
    method: 'GET',
    url: '/api/users',
    accept: 'application/ndjson',
});

const { status, data } = await promise;

if (status === 200) {
    console.log(data.length);
}
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].