Skip to content

Commit f68f8fb

Browse files
sverhoevenfdiblen
andauthored
Apply suggestions from code review
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
1 parent d184599 commit f68f8fb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ The value of the root is : -1.000000
167167

168168
| Pros | Cons |
169169
| --- | --- |
170-
| :heart: Very few moving parts, just C++ and Apache | :no_entry: Verbose Apache configuration |
171-
| :heart: Ancient proven technology | :no_entry: Unsuitable for long initialization or calculations |
170+
| :heart: Very few moving parts, just C++ and Apache web server | :no_entry: Complicated Apache web server configuration |
171+
| :heart: Proven technology | :no_entry: Not suitable for long initialization or calculations |
172172

173173
The classic way to run programs when accessing a url is to use the Common Gateway Interface (CGI). In the
174174
[Apache httpd web server](https://httpd.apache.org/docs/2.4/howto/cgi.html) you can configure a directory as a
175175
`ScriptAlias`, when visiting a file inside that directory the file will be executed. The executable can read the
176176
request body from the `stdin` and the response must be printed to the `stdout`. A response should consist of a
177177
content type such as `application/json` or `text/html`, followed by the content itself.
178-
For the web service we retrieve and assemble JSON documents using the [nlohmann/json.hpp](https://github.com/nlohmann/json/) library.
178+
For the web service, we parse and assemble JSON documents using the [nlohmann/json.hpp](https://github.com/nlohmann/json/) library.
179179

180180
We start writing the CGI script by importing the JSON library and starting the main function.
181181

@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
191191
{
192192
```
193193
194-
We should convert the JSON request body from the `stdin` to get the `epsilon` and `guess` values.
194+
We should parse the JSON request body from the `stdin` to get the `epsilon` and `guess` values.
195195
196196
```{.cpp file=cgi/cgi-newtonraphson.cpp}
197197
// this C++ snippet is appended to cgi/cgi-newtonraphson.hpp
@@ -200,15 +200,15 @@ We should convert the JSON request body from the `stdin` to get the `epsilon` an
200200
double guess = request["guess"];
201201
```
202202

203-
The rood can be found with
203+
The root can be found with
204204

205205
```{.cpp file=cgi/cgi-newtonraphson.cpp}
206206
// this C++ snippet is appended to cgi/cgi-newtonraphson.hpp
207207
rootfinding::NewtonRaphson finder(epsilon);
208208
double root = finder.solve(guess);
209209
```
210210
211-
And lastly return a JSON document with the result
211+
And lastly, return a JSON document with the result
212212
213213
```{.cpp file=cgi/cgi-newtonraphson.cpp}
214214
// this C++ snippet is appended to cgi/cgi-newtonraphson.hpp
@@ -226,7 +226,7 @@ This can be compiled with
226226
g++ -Icgi/deps/ -Icli/ cgi/cgi-newtonraphson.cpp -o cgi/apache2/cgi-bin/newtonraphson
227227
```
228228

229-
The CGI script can be tested from the command line without using a http request by piping a JSON document with
229+
The CGI script can be tested from the command line
230230

231231
```{.awk #test-cgi}
232232
echo '{"guess":-20, "epsilon":0.001}' | cgi/apache2/cgi-bin/newtonraphson
@@ -264,8 +264,8 @@ Start Apache httpd web server using
264264
/usr/sbin/apache2 -X -d ./cgi/apache2
265265
```
266266

267-
To test the [CGI script](http://localhost:8080/cgi-bin/newtonraphson) we can not use the web browser, but need to use http client like [curl](https://curl.haxx.se/).
268-
A web browser uses the [GET http request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) and `text/html` as content type, but the CGI script requires a [POST http request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) and JSON string as request body.
267+
To test the [CGI script](http://localhost:8080/cgi-bin/newtonraphson) we can not use a web browser, but need to use http client like [curl](https://curl.haxx.se/).
268+
Because, a web browser uses the [GET http request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) and `text/html` as content type, but the CGI script requires a [POST http request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) and JSON string as request body.
269269
The curl command with a POST request can be run in another shell with
270270

271271
```shell
@@ -283,9 +283,9 @@ Should return the following JSON document as a response
283283
}
284284
```
285285

286-
Instead of curl we could use any http client in any language to consume the web service.
286+
Instead of curl, we could use any http client in any language to consume the web service.
287287

288-
The problem with CGI scripts is when the program does some initialization, you have to wait for it each visit. It is
288+
The problem with CGI scripts is when the program does some initialization, you have to wait for it on each visit. It is
289289
better to do the initialization once when the web service is starting up.
290290

291291
## Python web service
@@ -294,7 +294,7 @@ better to do the initialization once when the web service is starting up.
294294

295295
| Pros | Cons |
296296
| --- | --- |
297-
| :heart: Python is great glue language | :no_entry: Pure Python is slower than C++ |
297+
| :heart: Python is a very popular language and has a large ecosystem | :no_entry: Pure Python is slower than C++ |
298298
| :heart: Web service discoverable and documented with OpenAPI specification | :no_entry: Exception thrown from C++ has number instead of message |
299299

300300
Writing a web service in C++ can be done, but other languages like Python are better equipped. Python has a big

0 commit comments

Comments
 (0)