Git Product home page Git Product logo

Comments (13)

giannif avatar giannif commented on June 11, 2024 1

@breadadams you should be good to go! here's a codesandbox showing it in action: https://codesandbox.io/s/fetch-api-in-express-kwfq8

The fetch api processes gifs after fetching, it normalizes some weirdness in our api responses and also helps us track which endpoint the gifs came from for our metrics.

If you have any issues lmk!

from giphy-js.

giannif avatar giannif commented on June 11, 2024 1

@devpascoe react-native support is on the wish list! but not exactly on our roadmap just yet, feel free to create an issue and we can hopefully get started on it

from giphy-js.

giannif avatar giannif commented on June 11, 2024 1

@budde377 I left it up to you to add the polyfill for fetch. In my experience, this is customary for libraries with polyfills. In the codesandbox I listed above, I used isomorphic-fetch.

I think this approach is best, because I wouldn't want to include a polyfill in the package that globally shims anything, it might override something in your application.

It also keeps the bundle size down

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@breadadams it wasn't a product requirement, but if headers is the only issue with node support then we can find a way to do it. In your environment, you can maybe require isomorphic-fetch before you require our lib. If there are other issues, lmk and I'll see what we can do about headers

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@breadadams released the new packages below that don't have the headers in fetch api, lmk if there are any other blockers for node!

  • @giphy/js-components: 2.4.3
  • @giphy/js-fetch-api: 1.5.3
  • @giphy/react-components: 0.7.3

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@breadadams I realized the headers are still referenced in our util package, will follow up when I have time to fix this

from giphy-js.

breadadams avatar breadadams commented on June 11, 2024

Ahh of course - no worries @giannif. Thanks for the effort here!

I ended up using the API directly in the end, which works for us as it's only a single request to the search API (you can see it here). However I'll be happy to move it over the the SDK once it's available 🙌

from giphy-js.

devpascoe avatar devpascoe commented on June 11, 2024

Something to look into is React Native support. Unable to get an iOS app running, comment out import { GiphyFetch } from '@giphy/js-fetch-api' and i am working again. Can use urls directly for now.

from giphy-js.

breadadams avatar breadadams commented on June 11, 2024

Thanks @giannif - I'll give it a shot this week!

@devpascoe react-native support would be nice! I'd open a separate issue for it and post the error logs you're getting. I'm sure they'll be able to sort it 😉💪

from giphy-js.

budde377 avatar budde377 commented on June 11, 2024

@giannif, I might be missing something, but it looks like you're still not supporting node, because you assume that fetch is available? I'm getting the error

Error: fetch is not defined
    at new FetchError (.../node_modules/@giphy/js-fetch-api/src/fetch-error.ts:5:9)
    at Object.<anonymous> (.../node_modules/@giphy/js-fetch-api/src/request.ts:37:30)
    ...

because of a call to fetch here https://github.com/Giphy/giphy-js/blob/master/packages/fetch-api/src/request.ts#L19 .

It might be worth using https://www.npmjs.com/package/isomorphic-fetch or allowing users to pass their own fetch in the GiphyFetch constructor?

Edit: A quick fix for this is assigning fetch globally

global.fetch = require('node-fetch')

from giphy-js.

breadadams avatar breadadams commented on June 11, 2024

Yeah, the polyfill should be handled at project level - not in the Giphy SDK 👍

from giphy-js.

budde377 avatar budde377 commented on June 11, 2024

@giannif That makes sense, thanks!

from giphy-js.

davidmm07 avatar davidmm07 commented on June 11, 2024

Works for me in Typescript with API's in Node

import fetch from "node-fetch";
declare var global: any;
global.fetch = fetch;

from giphy-js.

Related Issues (20)

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.