Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oakfang/xyquest
A proxy based HTTP requests utility
https://github.com/oakfang/xyquest
http proxy utility
Last synced: 6 days ago
JSON representation
A proxy based HTTP requests utility
- Host: GitHub
- URL: https://github.com/oakfang/xyquest
- Owner: oakfang
- License: mit
- Created: 2017-05-09T12:28:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-14T07:48:26.000Z (over 7 years ago)
- Last Synced: 2024-04-25T16:22:26.707Z (9 months ago)
- Topics: http, proxy, utility
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xyquest
A proxy based HTTP requests utility## Installation
`npm install --save xyquest`## Examples
**xyquest** is a flexible HTTP lib, which utilises adapters of the form:
```ts
interface Options {
uri: string,
method: string,
body?: any,
}type XyquestAdapter = (options:Options) => Promise;
```Included within is a simple adapter based on the **request** module.
### Usage with `request`
```js
const request = require('xyquest/request');
const xyquest = require('xyquest')(request, 'https://jsonplaceholder.typicode.com', { json: true });async function updateFirstComment(postId, patch) {
const [comment] = await xyquest.posts[postId].comments.get();
Object.assign(comment, patch);
await xyquest.comments[comment.id].put(comment);
return true;
}
```### Frontend Usage
You can use use the special `xyquest/es5` module to import an uglifiable version of this lib. Here's an example using it and the builtin `fetch` function:```js
function fetchAdapter(options) {
options.method = options.method.toUpperCase();
const body = new FormData();
body.append('json', JSON.stringify(options.body));
options.body = body;
return fetch(options.uri, options).then(response => response.json());
}const xyquest = require('xyquest/es5')(fetchAdapter, 'https://jsonplaceholder.typicode.com');
async function updateFirstComment(postId, patch) {
const [comment] = await xyquest.posts[postId].comments.get();
Object.assign(comment, patch);
await xyquest.comments[comment.id].put(comment);
return true;
}
```#### A note about `hyphenate`
**xyquest** options all have a `hyphenate` key that is set to `true` by default. It ensures that calling props like `xyquest.userControls` will be translated to the url `/user-controls`. If your API does'nt follow this convention, you can set it to `false` globally or individually.