Should I do API requests server side or client side? Should I do API requests server side or client side? express express

Should I do API requests server side or client side?


There's are two key considerations for this question:

  1. Do calls incur any data access? Are the results just going to be written to the screen?
  2. How & where do you plan to handle errors? How do you handle throttling?

Item #2 is really important here because web services go down all of the time for a whole host of reasons. Your calls to Bing, Amazon & Last FM will fail probably 1% or 0.1% of the time (based on my experiences here).

To make requests users server-side JS you probably want to take a look at the Request package on NPM.


It's often good to abstract away your storage and dependent services to isolate changes and offer a consolidated and consistent web api for your application. But sometimes, if you have a good hypermedia web api (RESTful responses link to other resources), you could reference a resource link from another service in the response from your service (ex: SO request could reference gravatar image/resource of user). There's no one size fits all - it depends on whether you want to encapsulate the dependency or integrate with it.

It might be beneficial to make the web-api requests from your service exposed via expressjs as your own web-apis.

Making http web-api requests is easy from node. Here's another SO post covering that:

HTTP GET Request in Node.js Express


well, the way you describe it I think you may want to fetch data from amazon, lastfm and so on, process it with node, save it in your database and provide your own api.

you can use node's http.request() to fetch the data and build your own rest api with express.js