ladjs / frisbee Goto Github PK
View Code? Open in Web Editor NEW:dog2: Modern fetch-based alternative to axios/superagent/request. Great for React Native.
Home Page: https://niftylettuce.com/frisbee
License: MIT License
:dog2: Modern fetch-based alternative to axios/superagent/request. Great for React Native.
Home Page: https://niftylettuce.com/frisbee
License: MIT License
Hi guys, can someone explain me how to add a querystring to my request? Reading the documentation it says I can do it but I haven't found the way to do it.
Imagine my baseURI
is: https://mybaseuri.com/
My service is: users
And I want to add: userId=0209206245902063
So it should look like https://mybaseuri.com/users?userId=0209206245902063
An example would be really appreciated. Thanks in advance.
Currently Frisbee converts body into a query string for get
and delete
methods. That's weird because it's an artificial limitation and there is no way to workaround it. On the other hand it requires additional tooling to add a query string to an url.
I propose to bring get
and delete
methods in line with the rest of methods and introduce a params
option, that will stringify params and add it to url. I would be happy to send PRs!
When you define a arrow function within a class method you no longer have to resort to assigning the 'this' context to refer to the class.
Arrow methods use the direct parent context when referring to 'this'.
https://github.com/niftylettuce/frisbee/blob/master/src/frisbee.js#L57
Source: http://codepen.io/somethingkindawierd/post/es6-arrow-functions-this
When I first learned this, arrow methods become really exciting.
Is there a way that some helpful error messages can be thrown rather than just 'Network request failed' because that does not really tell anything about the failure. Any help will be appreciated.
โช Add yourself or someone you know!
as title
This does not seem to support 'multipart/form-data' for file uploading?
When I test this:
const client = new Frisbee({baseURI: 'http://localhost:3000'});
console.log(client);
I've got this:
console.log src\sync\tests\sync-http-client.test.js:13
Frisbee {
opts: { baseURI: 'http://localhost:3000' },
parseErr:
Error: Invalid JSON received from http://localhost:3000
I haven't done any requests before calling that code, so I must assume this is some kind of bug?
This says in several places (in the README, on npm) that fetch is part of ECMAScript (6, or 7) but that's not correct. It's defined by a WHATWG spec. This in particular doesn't make sense:
Why don't you have an ES5 compiled version readily available in this git repo?
As this module relies on ES6 fetch, there is currently no backwards compatibility for ES5
as a exemple, i make GET over 'http://api.test.com/products/?name=¶m1=¶m2=false¶m3=false¶m4=false'
this kind of call works on version 1.6.0 but didn't work on version 1.6.4.
it's giving me a authentication error (401). but the token is past correctly.
i have no idea about what change between the two version but something go wrong.
Started working on polishing the Android version of our React Native application, and I came across a strange issue that I'm not sure how to solve.
I was not able to login to the application once I got it building. So, I did some debugging with log statements and found that the session token and other information from the login api call was not being saved properly. Doing console.log(response.body) showed all the information I expected, but doing console.log(response.body.session_token) gave undefined. On a hunch, I tried passing the body into JSON.parse and found that I was able to get the session token and other data just fine.
Going back to iOS however throws an error on the JSON.parse line, because response.body is already an object and not a string.
Is there something going on here between the operating systems? Looking at the frisbee source shows that it should be calling JSON.parse on my behalf, so I am very confused at the discrepancy here. I'd rather not pepper the code with try catches to parse the response properly on both platforms.
Hi, I'm trying to test my application with jest and noticed, that I don't have the http methods on my Frisbee instance.
Scenario:
import Frisbee from 'frisbee';
// ...
const api = new Frisbee('http://example.com');
api.get // undefined
Result: api.get
is undefined
When I link frisbee locally with yarn link
and import the src
:
import Frisbee from 'frisbee/src';
// ...
const api = new Frisbee('http://example.com');
api.get // function(...) {...}
Result: api.get
is defined
Could not find out why. The code in frisbee/dist/index.js
seems to implement these methods ๐คทโโ๏ธ
Thanks for ur help ๐
It seems that babel-runtime
is an undocumented package, the official babel documentation, suggest using either babel-polyfill
(not a good idea for a lib) or Facebook's regenerator-runtime/runtime
On a higher level, I think Frisbee should not be using async/await and probably should stick to simple Promises. async/await are Promises behind the hood, and make it harder to reason about asynchronous execution flows, and you still end up having to interact with Promises for things such as Promise.all
.
async/await
were introduced to help expand Javascript to more programmers who are familiar with imperative programming and have a hard time breaking down nested calls, but generally should not be used by a library, especially when it introduces a runtime dependency.
It would be nice for downstream error handling if frisbee had custom error types like FrisbeeRequestError
, or even allowed for specifying error types in config.
Frisbee JSON.parse the response even when the native json responsive is available. JSON.parse is slow and so Frisbee should check if the natively parsed response is already available.
How do you log request / response for debugging purposes with Frisbee?
Would be great to add some optional request logging with something like:
new Frisbee({
logger: myLogger
});
Waiting on Earnest-Labs/eslint-config-earnest-es7#30
In package.json we have several rules turned off in the "xo" property block. We should remove these overridden rules and rewrite the codebase so that the rules are obeyed.
Looking briefly through the docs, I wasn't able to find support for XML responses from a server (e.g. response of type Document to allow for XML dom parsing). Did I miss something? Any advice on a set up to deal with both XML and JSON responses from a server?
So we can do stuff like this without needing querystring modules.
let params = new URLSearchParams();
params.append('key', 'foobar');
params.append('language', 'en');
params.append('location', [
coords.latitude,
coords.longitude
].join(','));
params.append('radius', 500);
googleapi.get(
'/maps/api/place/nearbysearch/json',
{ body: params },
(err, res, message) => {
console.log('googleapi', 'err', err,
'res', res, 'message', message);
}
);
Hi,
When I am calling get its returning session expired. API is not getting cookie value along with get request. I can see the set-Cookie value in initial login(post) request. But its not using for next API calls. This is happening only in Android. iOS is working perfectly fine.
Any Idea what I am missing here.
Whenever making a POST request, the variables passed in body are empty. When passing the following to a POST endpoint, the result is {}
const res = await api.post('/test', {
body: {"test" : "test"}
});
It works perfectly well with GET requests to GET endpoints.
I was very enthusiastic about this package but had to switch back to Axios after figuring out that Frisbee is unable to do requests that are relative to current domain like api.get('/api/endpoint')
.
Host environment variable isn't always available or practical. I would suggest to make it optional, as it is in every other library around. If mandatory baseURI is there to address native platforms, this could be handled by platform detection.
It would be nice if all of us know what changed in this package.
Thanks !
Is there something I'm missing after upgrading to 1.0.5 with the new "import" syntax? Continually getting this error now:
Unable to resolve module babel-runtime/regenerator from /Users/Mac/Desktop/Mobile/node_modules/frisbee/lib/frisbee.js: Unable to find this module in its module map or any of the node_modules directories under /Users/node_modules/babel-runtime/regenerator and its parent directories
Help!
Hello! I am trying to set up a phone verification using https://github.com/joinspontaneous/react-native-phone-verification
I am currently only using their example code, given here: https://github.com/joinspontaneous/react-native-phone-verification/blob/master/example/index.ios.js
However, I get this result when trying to run their code:
Of course I have tried with my actual phone number, same result. I don't know how to approach this issue, and I am fairly new with React Native. Any help appreciated! Thanks! - Ralfi
Is there a way to set timeouts on requests made via Frisbee?
when i refresh the page the information response is still the old one.
I have include import "isomorphic-fetch" but either way I'm getting "Frisbee {opts: Object, parseErr: Error: Invalid JSON received from ..." on the response.
Hi,
I am using the latest verison of Chrome on OS X (Version 50.0.2661.102 (64-bit)
), with Frisbee
, and response.body
will return ReadableByteStream
instead of an expected response object as built by the result of parsing a json response.
This seems to be the standard, but then why would the frisbee doc give this example? Trying to read the response with response.json()
will return the following error: Uncaught (in promise) TypeError: Already read
.
@niftylettuce when after login there is a token key dispatched from the server and it should be saved in the device.
Can I use auth('123123123ggg')
as the one string for future? Can i expect to see the header contains
Authorization: 123123123ggg
as the authorised token? Is it a way to store this piece of string into frisbee for future header use?
Is abort() or similar function available? Fetch is known to not have abort() in place. I am considering to use frisbee in React Native but am thinking to cancel the connections when component unmounts. Or, could it be that, for fetch-based libraries, it is not necessary to have abort() function in place?
~RT
We upgrade node to node 8 this error appear
Please publish a new version so we can use other package, now its blocking we add new package.
Thanks
I'm using frisbee in an expo project, consuming a Python (Flask-Classful) API. Whenever my API returns a non-ok
response, I get a stack trace as follows:
Stack trace:
node_modules/frisbee/lib/index.js:184:40 in _callee$
node_modules/regenerator-runtime/runtime.js:62:44 in tryCatch
node_modules/regenerator-runtime/runtime.js:288:30 in invoke
node_modules/frisbee/lib/index.js:7:103 in asyncGeneratorStep
node_modules/frisbee/lib/index.js:9:212 in _next
node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
node_modules/promise/setimmediate/core.js:123:25 in <unknown>
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:152:14 in _callTimer
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:200:17 in _callImmediatesPass
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:464:30 in callImmediates
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:320:6 in __callImmediates
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6 in <unknown>
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:297:10 in __guard
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:17 in flushedQueue
...
It's kind of difficult for me to debug, because my local node_modules/frisbee/lib/index.js
is so different to the code in git, I believe due to regenerator. I'd be happy to learn how to debug this more smartly. I've read about babel and regenerator but as a newbie to this ecosystem it's a bit rough. I don't know if the issue is in frisbee or regenerator, and I don't understand why frisbee uses regenerator at all, as I don't see any function*
in the code.
However, by judicious use of console.log
, I understand that the problem occurs in case 27:
in the transpiled code:
case 27:
resolve(res);
return _context.abrupt("return");
I believe that the original code is at https://github.com/niftylettuce/frisbee/blob/master/src/index.js#L210 (end of the if (!res.ok)
block.
I hope this is enough information to understand what the issue is, but if not, I'm happy to provide more, just let me know what you need. I'm using Expo 32 and node 10.15.2.
The project description reads:
Stripe-inspired API wrapper around ES6/ES7's fetch() method
but fetch
is a WHATWG browser API spec, not an ES6/7 feature.
Right now it is only Basic - https://github.com/niftylettuce/frisbee/blob/master/src%2Ffrisbee.js#L203
it should handle JWT and so on
Something like this:
const fetch = require('node-fetch');
new Frisbee({
fetch
});
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.