roonie007 / axiod Goto Github PK
View Code? Open in Web Editor NEWPromise based HTTP client for Deno
Promise based HTTP client for Deno
I don't know if this is a bug or I'm using it wrong:
import axiod from "https://deno.land/x/axiod/mod.ts";
await axiod.get("https://httpbin.org/redirect/:1")
console.log("Test")
Results:
โ deno run --allow-all ./main.ts
error: Uncaught TypeError: stream is locked.
at new ReadableStreamDefaultReader (deno:op_crates/fetch/11_streams.js:358:15)
at acquireReadableStreamDefaultReader (deno:op_crates/fetch/11_streams.js:1029:20)
at ReadableStream.getReader (deno:op_crates/fetch/11_streams.js:553:16)
at Response.arrayBuffer (deno:op_crates/fetch/26_fetch.js:870:50)
at Response.text (deno:op_crates/fetch/26_fetch.js:858:29)
at mod.ts:192:25
at async main.ts:13:1
Hello, I think that the latest versions are not published on the deno land registry.
For example, here is an example of code where the queryParams are passed via the params parameter:
async function fetchArtworks() {
const params = {
fields: 'id,title',
page: 10
}
const config = {
url: `https://api.artic.edu/api/v1/artworks`,
method: "get" as const,
params,
};
const res = await axiod.request(config);
console.log('res', res)
return res.data;
}
void fetchArtworks()
When I run it with the import:
import axiod from "https://deno.land/x/axiod/mod.ts";
all fields are returned and the page is not the right one.
However, when I use the import:
import axiod from "https://raw.githubusercontent.com/roonie007/axiod/master/mod.ts";
it works correctly.
The last release is from August 2020 and the commit that fixes the problem is from November 2020. Is there any plan to publish the latest versions on the deno land registry ?
const axiodOrAxios = typeof axiod !== 'undefined' ? axiod : typeof axios !== 'undefined' ? axios : undefined;
const client = axiodOrAxios.create({ baseURL: 'https://httpstat.us' });
await client.get('/200');
console.log('Success');
await client({ url: '/200' });
console.log('Success');
Expected output (axios
-like) :
Success
Success
Actual output :
Success
error: Uncaught (in promise) TypeError: Invalid URL
return fetch(url, fetchRequestObject).then(async (x) => {
^
at opUrlParse (deno:ext/url/00_url.js:52:26)
at new URL (deno:ext/url/00_url.js:331:20)
at new Request (deno:ext/fetch/23_request.js:307:27)
at deno:ext/fetch/26_fetch.js:433:29
at new Promise (<anonymous>)
at fetch (deno:ext/fetch/26_fetch.js:429:20)
at Function.request (https://deno.land/x/[email protected]/mod.ts:252:10)
at Object.axiod (https://deno.land/x/[email protected]/mod.ts:23:16)
Thanks
`const resolvers = {
Query: {
getLaunches: (parent: any, context: any, info: any) => {
return axiod.get("https://api.spacexdata.com/v3/launches").then(res => res.data)
}
}
}`
Hello. The example from the readme returns an error. Problem with responseType.
Example code:
axiod({ method: "get", url: "http://bit.ly/2mTM3nY", responseType: "stream", }).then((response) => { response.data.pipe(fs.createWriteStream("ada_lovelace.jpg")); });
Error:
[ERROR]: Argument of type '{ method: string; url: string; responseType: string; }' is not assignable to parameter of type 'string | IRequest'. Object literal may only specify known properties, and 'responseType' does not exist in type 'IRequest'.
I used axiod.create with a baseURL but i got the error "error: Uncaught URIError: relative URL without a base"
The fuction dont use my baseURL
I also went through this as a third party contributor - see denoland/dotland#1407
Hey, I launch the very basic code to test if the package worked and I got this :
error: Uncaught (in promise) TypeError: stream is locked.
at new ReadableStreamDefaultReader (deno:op_crates/fetch/11_streams.js:358:15)
at acquireReadableStreamDefaultReader (deno:op_crates/fetch/11_streams.js:1029:20)
at ReadableStream.getReader (deno:op_crates/fetch/11_streams.js:553:16)
at Response.arrayBuffer (deno:op_crates/fetch/26_fetch.js:870:50)
at Response.text (deno:op_crates/fetch/26_fetch.js:858:29)
at mod.ts:192:25
code :
import axiod from "https://deno.land/x/axiod/mod.ts";
axiod.get("https://google.fr").then((response) => {
// response
console.log(response);
});
thanks
Hi,
at the moment FormData is supported as body, and is handed to fetch without modification (mod.ts:78).
How about doing the same for URLSearchParams? In fetch both types are treated differently, e.g. for URLSearchParams the content-type header is set to application/x-www-form-urlencoded;charset=UTF-8, whereas FormData is treated as multipart/form-data. So in my opinion it would make sense to consider these scenarios in axiod as well. What do you think?
Hi, thanks for the nice project!
const resp = await axiod({
url: ...,
method: 'GET',
headers: {
...
}
})
console.log(resp.headers['content-type'])
It logs undefined
.
The actual response in the Network tab clearly has keys and values
Describe the bug
Deno 1.4.0 introduced stricter checks on the import and export of types for all users using the --unstable flag. These (presumably) will be integrated with Deno stable in an upcoming release.
See relevant section in release blog post: https://deno.land/posts/v1.4#stricter-type-checks-in-code--unstablecode
To Reproduce
Import this module in a file and use deno run --unstable to execute the file.
Note there are several errors:
error: TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import {
^
at https://deno.land/x/[email protected]/mod.ts:3:1
The import should work without throwing typescript errors relating to type imports and exports.
Package & Environment Details
$ deno --version
deno 1.4.6
v8 8.7.220.3
typescript 4.0.3
const axiodOrAxios = typeof axiod !== 'undefined' ? axiod : typeof axios !== 'undefined' ? axios : undefined;
const client = axiodOrAxios.create({ baseURL: 'https://httpstat.us' });
let _config;
client.interceptors.request.use(config => {
_config = config;
return config;
});
client.interceptors.response.use(
response => {
console.log(_config === response.config);
return response;
},
error => {
console.log(_config === error.config);
return Promise.reject(error);
}
);
await client.get('/200');
await client.get('/401', { validateStatus: () => true });
Expected output (axios
-like) :
true
true
Actual output :
false
false
Thanks
error: Relative import path "url-join" not prefixed with / or ./ or ../ from "https://deno.land/x/[email protected]/mod.ts"
The command '/bin/sh -c deno cache --unstable server.ts' returned a non-zero code: 1
ERROR: Service 'ngombe_loan_api' failed to build : Build failed.
Any help? am forced to downgrade for it to work
Thanks
Is it possible to make a GraphQL request like
{
users {
id
}
}
Axios supports Type Generics
https://github.com/axios/axios/blob/82c94555917834770bd1389fc0b4cd9ba35ec3fe/index.d.ts#L151
and
https://github.com/axios/axios/blob/82c94555917834770bd1389fc0b4cd9ba35ec3fe/index.d.ts#L83
so if you now the response type you can easily create a interface pass it to the post request like
const data = await axios.post<Result>();
data.data // Autocomplete because `data.data` is `typeof Result`
interface Result {
nice: string;
data: string;
}
Can you add more type to auto parse (e.g. ArrayBuffer) please?
And also add responseType to request Options
I was using 0.21 and started tracking down the same problem as issue #2. It looks like PR #14 resolves this problem, but it isn't published as an update available to https://deno.land/x.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.