|
| 1 | +# HTTP Proxy Sample |
| 2 | + |
| 3 | +## Dependencies |
| 4 | + |
| 5 | +This sample requires the [Boost.Beast](https://www.boost.org/doc/libs/1_82_0/libs/beast/doc/html/index.html) |
| 6 | +header-only library. If you are using [vcpkg](https://github.com/microsoft/vcpkg), it can install that component |
| 7 | +for you on-demand. Otherwise, you may need to install it separately if you have a selective installation of |
| 8 | +`Boost`. |
| 9 | + |
| 10 | +## Server |
| 11 | + |
| 12 | +The `server` executable listens for HTTP connections on http://127.0.0.1:8080/ (port 8080 of `localhost`). It |
| 13 | +is expecting POST requests with a JSON payload in the request body that looks like this: |
| 14 | +```json |
| 15 | +{ |
| 16 | + "query": "GraphQL query document goes here", |
| 17 | + "operationName": "(optional) GraphQL operation name goes here", |
| 18 | + "variables": "(optional) JSON object embedded in a string with GraphQL operation variables" |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +It has a single thread accepting requests, and it uses C++20 coroutines. The GraphQL service which actually |
| 23 | +resolves the requests is the same Star Wars learning sample in [../learn](../learn/). |
| 24 | + |
| 25 | +## Client |
| 26 | + |
| 27 | +The `client` executable works like most of the other command line samples, it can take a single argument for |
| 28 | +the operation name and it will read the GraphQL query document from standard input. It packages the query |
| 29 | +parameters in variables for a pre-parsed [query/query.graphql](query/query.graphql), and it implements an |
| 30 | +in-proc GraphQL service with the [schema/schema.graphql](schema/schema.graphql) schema using an asynchronous |
| 31 | +field resolver. The field resolver packages the parameters into a JSON message and sends it to the `server` |
| 32 | +process waiting on http://127.0.0.1:8080/. |
| 33 | + |
| 34 | +When it gets a response, `client` uses the same pre-parsed query in [query/query.graphql](query/query.graphql) |
| 35 | +to parse the result and return the JSON document in the field returned from the `server` process. |
| 36 | + |
| 37 | +As long as you start the `server` process first, the behavior of `client` should be almost identical to the |
| 38 | +`learn` executable sample produced by [../learn](../learn/). |
0 commit comments