From 77c12422436e94b38686a646b7bf32e9f8ab1071 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Thu, 18 Jun 2020 11:48:18 +0200 Subject: [PATCH] Explain why curl --- README.md | 8 ++++++-- README.outline.md | 3 --- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cb3e49f..3d597ae 100644 --- a/README.md +++ b/README.md @@ -283,12 +283,14 @@ Start Apache httpd web server using /usr/sbin/apache2 -X -d ./cgi/apache2 ``` -And in another shell call CGI script using curl +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/). +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. +The curl command with a POST request can be run in another shell with ```shell curl --request POST \ - --header "Content-Type: application/json" \ --data '{"guess":-20, "epsilon":0.001}' \ + --header "Content-Type: application/json" \ http://localhost:8080/cgi-bin/newtonraphson ``` @@ -300,6 +302,8 @@ Should return the following JSON document as a response } ``` +Instead of curl we could use any http client in any language to consume the web service. + The problem with CGI scripts is when the program does some initialization, you have to wait for it each visit. It is better to do the initialization once when the web service is starting up. diff --git a/README.outline.md b/README.outline.md index 7304e91..f95a584 100644 --- a/README.outline.md +++ b/README.outline.md @@ -1,8 +1,6 @@ # JavaScript web service -- OK to test with curl not browser? - # JavaScript web application - how to use wasm in webbrowser @@ -21,4 +19,3 @@ - web framework - long running tasks (concept, Python toolset, JavaScript toolset): consider splitting off into 1 or 2 separate documents; in the main document describe a what is basically a Promise and point to the relevant other document - single page application -- Optional add pros and cons per section