@aspida/node-fetch
Advanced tools
Comparing version 1.10.3 to 1.11.0
@@ -1,2 +0,2 @@ | ||
import { AspidaClient } from 'aspida'; | ||
import { AspidaClient, dataToURLString } from 'aspida'; | ||
import fetch, { RequestInit, Response } from 'node-fetch'; | ||
@@ -6,2 +6,3 @@ export declare type FetchConfig = RequestInit & { | ||
throwHttpErrors?: boolean; | ||
paramsSerializer?: typeof dataToURLString; | ||
}; | ||
@@ -8,0 +9,0 @@ export declare class HTTPError extends Error { |
@@ -91,3 +91,3 @@ "use strict"; | ||
return function () { return __awaiter(_this, void 0, void 0, function () { | ||
var request, res; | ||
var request, serializer, res; | ||
var _a; | ||
@@ -99,3 +99,4 @@ var _b, _c, _d; | ||
request = (0, aspida_1.optionToRequest)(params, type); | ||
return [4 /*yield*/, client("".concat((_c = (_b = request === null || request === void 0 ? void 0 : request.config) === null || _b === void 0 ? void 0 : _b.baseURL) !== null && _c !== void 0 ? _c : baseURL).concat(url).concat((request === null || request === void 0 ? void 0 : request.query) ? "?".concat((0, aspida_1.dataToURLString)(request.query)) : ''), __assign(__assign(__assign({ method: method }, config), request === null || request === void 0 ? void 0 : request.config), { body: request === null || request === void 0 ? void 0 : request.httpBody, headers: __assign(__assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), (_d = request === null || request === void 0 ? void 0 : request.config) === null || _d === void 0 ? void 0 : _d.headers), request === null || request === void 0 ? void 0 : request.headers) })).then(function (res) { | ||
serializer = (config === null || config === void 0 ? void 0 : config.paramsSerializer) || aspida_1.dataToURLString; | ||
return [4 /*yield*/, client("".concat((_c = (_b = request === null || request === void 0 ? void 0 : request.config) === null || _b === void 0 ? void 0 : _b.baseURL) !== null && _c !== void 0 ? _c : baseURL).concat(url).concat((request === null || request === void 0 ? void 0 : request.query) ? "?".concat(serializer(request.query)) : ''), __assign(__assign(__assign({ method: method }, config), request === null || request === void 0 ? void 0 : request.config), { body: request === null || request === void 0 ? void 0 : request.httpBody, headers: __assign(__assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), (_d = request === null || request === void 0 ? void 0 : request.config) === null || _d === void 0 ? void 0 : _d.headers), request === null || request === void 0 ? void 0 : request.headers) })).then(function (res) { | ||
return !res.ok && (config === null || config === void 0 ? void 0 : config.throwHttpErrors) ? Promise.reject(new HTTPError(res)) : res; | ||
@@ -102,0 +103,0 @@ })]; |
{ | ||
"name": "@aspida/node-fetch", | ||
"version": "1.10.3", | ||
"version": "1.11.0", | ||
"description": "node-fetch client for aspida", | ||
@@ -30,3 +30,6 @@ "author": "Solufa <solufa2020@gmail.com>", | ||
"aspida": "^1.7.1" | ||
}, | ||
"devDependencies": { | ||
"qs": "^6.11.0" | ||
} | ||
} |
# @aspida/node-fetch | ||
<br /> | ||
@@ -85,4 +86,31 @@ <img src="https://aspida.github.io/aspida/logos/png/logo.png" alt="aspida" title="aspida" /> | ||
### Serialize GET parameters manually | ||
`src/index.ts` | ||
```typescript | ||
import fetch from "node-fetch" | ||
import aspida, { HTTPError } from "@aspida/fetch" | ||
import qs from "qs" | ||
import api from "../api/$api" | ||
const fetchConfig = { | ||
paramsSerializer: params => qs.stringify(params) | ||
} | ||
const client = api(aspida(fetch, fetchConfig)) | ||
;(async () => { | ||
const users = await client.v1.users.$get({ | ||
// config: { paramsSerializer: (params) => qs.stringify(params) }, | ||
query: { ids: [1, 2, 3] } | ||
}) | ||
console.log(users) | ||
// req -> GET: /v1/users/?ids%5B0%5D=1&ids%5B1%5D=2&ids%5B2%5D=3 | ||
// decoded -> ids[0]=1 &ids[1]=2 &ids[2]=3 | ||
// res -> [{ id: 1, name: "taro1" }, { id: 2, name: "taro2" }, { id: 3, name: "taro3" }] | ||
})() | ||
## License | ||
@aspida/node-fetch is licensed under a [MIT License](https://github.com/aspida/aspida/blob/master/packages/aspida-node-fetch/LICENSE). | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16233
141
116
1