From a41b463b785ac9ae634ce25102662f2c1b43b436 Mon Sep 17 00:00:00 2001 From: M Date: Mon, 5 Feb 2024 23:06:08 +0330 Subject: [PATCH 1/2] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 03f1945..db6b9f5 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,25 @@ finally run `./target/release/fig run ./example.fig` *The output should be `Hello World`.* Also, you can test out fig files in `examples` folder. + +# Server-side +You can write a server side applications with FigLang, FigCli has an command called `server` That will listen on address and port you specified, +each time an request arives the cli will run the script and pass the HTTP request content to the main function. + +### Server command +Here is an example usage of the `server` command: + +`./target/release/fig server ./test.fig --addr localhost:8080` + +### Example server side code +Here is an example source code of using server feature in FigCli, It's just like an ordinary Fig program but the main function will get one parameter, Which will contain the content of HTTP request as `char[]` or a string. + +`test.fig`: + +``` +export fn main (request: char[]): char[] { + // Your code +} +``` + +The `main` function must return the HTTP response as an `char[]` or string. The return will be your app's response to the request. From e49d7dc62fe484dfb2d1d1f8f270ffab4874bdf6 Mon Sep 17 00:00:00 2001 From: M Date: Mon, 5 Feb 2024 23:09:48 +0330 Subject: [PATCH 2/2] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index db6b9f5..ad8b4a0 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,5 @@ export fn main (request: char[]): char[] { ``` The `main` function must return the HTTP response as an `char[]` or string. The return will be your app's response to the request. + +Also checkout the [server.fig](https://github.com/fig-lang/fig/blob/main/examples/server.fig) example file there is a lot of helper functions that will make the generation of response, Or reading the request easier.