Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

Does the App create a HTTP client and then connect to its own API in order to create the response? #1

Open
mackross opened this issue Jul 24, 2014 · 3 comments

Comments

@mackross
Copy link

Am I following this right?

  1. A web page http request is initiated by the browser.
  2. The app handler parses the request and uses the api client to create a new http request to itself but on the api routes.
  3. The api handler handles the request from the api client and fetches/changes the relevant data in the datastore.
  4. The api handler marshals a JSON response and sends it back to the api client.
  5. The app then unmarshals the JSON response from the api client and renders it in a template?
@sqs
Copy link
Member

sqs commented Jul 24, 2014

That is correct.

On Jul 23, 2014, at 21:44, mackross notifications@github.com wrote:

Am I following this right?

A web page http request is initiated by the browser.
The app handler parses the request and uses the API client to create a new http request to itself but on to api routes.
The api handler handles the request from the api client and fetches/changes the relevant data in the datastore.
The api handler marshals a JSON response and sends it back to the api client.
The app then unmarshals the JSON response from the api client and renders it in a template?

Reply to this email directly or view it on GitHub.

@mackross
Copy link
Author

What is the benefit of having it like this rather than having the app use the same data interface as the api? It seems like more overhead (extra marshal & unmarshal) and added complexity on every web request.

@sqs
Copy link
Member

sqs commented Jul 24, 2014

It does use the same interface. Why not just do all of the logic in the same Go process? We want to load balance, cache, and instrument our API calls. While this simple app obviously doesn't require those, it's a demonstration of what we do in Sourcegraph.com. For example, some of our frontend handlers make 10 API calls in parallel, and it's nice that we can use standard HTTP caching, and AWS Elastic Load Balancers, and appmon (our HTTP instrumenter) instead of inventing new things. This all reduces complexity.

Also, as a practical matter, the de/serialization time is negligible.

On Jul 23, 2014, at 23:42, mackross notifications@github.com wrote:

What is the benefit of having it like this rather than having the app use the same data interface as the api? It seems like more overhead (extra marshal & unmarshal) and added complexity on every web request.


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants