GithubHelp home page GithubHelp logo

ladjs / frisbee Goto Github PK

View Code? Open in Web Editor NEW
1.1K 22.0 70.0 1.63 MB

:dog2: Modern fetch-based alternative to axios/superagent/request. Great for React Native.

Home Page: https://niftylettuce.com/frisbee

License: MIT License

JavaScript 97.72% HTML 2.28%
api-wrapper superagent frisbee fetch fetch-api whatwg whatwg-fetch xhr request file-upload

frisbee's People

Contributors

acecode avatar akmjenkins avatar almouro avatar aretecode avatar assem-hafez avatar bradjones1 avatar brentvatne avatar casoetan avatar davidgovea avatar hawkrives avatar hosmelq avatar jmoutte avatar jordandenison avatar kesha-antonov avatar kkirby avatar montogeek avatar niftylettuce avatar omgimalexis avatar rmevans9 avatar sampsasaarela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frisbee's Issues

Add querystring

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.

Body handling for get and delete methods

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!

Helpful error messages when the request fails

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.

Estrange parseErr

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?

Incorrectly describes Fetch as part of ES

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

  • Availability of fetch has little to do with ES version support, except for Promise, which can be polyfilled in ES5.
  • The expectation would likely be for an ES5 version on npm, not in the source repo.

React Native: Android vs iOS JSON parsing

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.

http methods not available in jest tests

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 ๐Ÿ™

babel-runtime seems to be deprecated

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.

Custom error types

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.

Debug logging

How do you log request / response for debugging purposes with Frisbee?

Logger hook

Would be great to add some optional request logging with something like:

new Frisbee({
  logger: myLogger
});

XML response support

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?

Embed https://www.npmjs.com/package/urlsearchparams directly in package

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);
          }
        );

Android Cookies are not persisted across network requests

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.

Body parameters are empty in POST

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.

Optional baseURI

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.

Missing babel-runtime?

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!

Network Request Failed

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:
simulator screen shot - iphone 8 - 2018-07-02 at 13 21 34

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

res.body return a ReadableByteStream object on Chrome

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.

Authorization header should be customizable

@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?

Abort() function

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?

Error / stack trace whenever API returns non-ok response

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.

Incorrect project description

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.