0

I see alot of other questions on this but as Node.js is a server-side language "Etag support" seems to be referring to the a nodejs app creating, sending and handling what code to give back to their client. In my case I am requesting and not sending resources and saving all 200 responses to my firebase db for mobile users to use and updating when I get another 200 response (rather than the 304) when I match the Etag value to If-None-Match header to send back out for additional requests to see if there is a change in the resource.

Also, what's the proper terminology in this case. Am I the client and my mobile app users are my client, so they're the client's client?

I using reqest and was wondering if there is an easier way than setting a local etag variable, check if it's set if not, then use one set of headers one without an empty 'If-None-Match' and another with it, and use it when you grab it in the response grab like so

 function callback(error, response, body) {
        if (!error && response.statusCode == 200) {
          var info = body;
          var etag = headers.etag;
          returnEtag(etag)

then having to grab and return it in the returnEtag() function and use it in the second set of headers and so on.

This gets messy not to mention I'd have to do this through my entire app to manage each etag for each different request there an simpler/easier way. Are there any module with support for handling this out of the box?

The documentation states i should do the following

All responses return an HTTP Cache-Control header. It’s content indicates how long a cached response can be used to reduce unnecessary API requests. Clients accessing the this API MUST regard this information.

In addition to that, each response returns an HTTP ETag header. It’s content is to be used in subsequent requests to the same resource in an HTTP If-None-Match header. The API will then return a status code 304 Not Modified if the cached information is still valid. Clients accessing the This API MUST use this technique, also known as conditional GET.

Im using my own server to access this API then saving that data to a firebase that can be accessed my users on a mobile app (keeping app my keys with this other companies api away from the mobile app users).

Community
  • 1
  • 1
garrettmac
  • 8,417
  • 3
  • 41
  • 60
  • Etags are not sent by the client. These are tags from a server to a client. Same with "If-None-Match" so I am confused about what you are trying to do. I am not aware that a server does anything with etags if it receives one from a client. I'm not sure that even makes sense. – Rob Apr 11 '16 at 03:23
  • @Rob Maybe I'm misunderstanding something so I updated the question by adding more info at the bottom – garrettmac Apr 11 '16 at 03:30
  • A request is made by a client to a server. That server returns a response to the client which includes a Cache-Control header and an ETag. The client can then determine if it needs to fetch that content from the network or from cache based on the Cache-Control header and ETag. A server does not make requests to clients nor get those headers so it sounds like your getting these names and who requests from who mixed up. – Rob Apr 11 '16 at 03:41
  • 1
    ok pew, I tried to make the question as clear as I can but as I stated in the restructured question If Im getting data from an API and relaying it to my users am I the client and my mobile app users are my client, so they're the client's client? Thanks for taking the time to help. – garrettmac Apr 11 '16 at 03:59
  • Conceptually the app is dual role or ia proxy. In a dual role, it servers to your mobile clients, it processes data and is a client to a remote server's API. If your web app merely serves as a proxy between the mobile devices and remote APIs, then in that case that the mobile clients can be said to have a direct client/server with the remote APIs, as proxies are considered "transparent" in client/server relationships. Client-server relationships often traverse a number of routers, hubs, gateways and proxies, but we don't consider the overall relationship client-client-client-client-server. – Mark Stosberg Sep 21 '20 at 16:06

0 Answers0