From 73d39725b999f01bda04ac4f3b31f485443ac75c Mon Sep 17 00:00:00 2001 From: AzerothA Date: Sat, 16 Mar 2024 23:12:05 +0330 Subject: [PATCH] Server section moved to book --- README.md | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/README.md b/README.md index 4f6603f..4060a7c 100644 --- a/README.md +++ b/README.md @@ -35,34 +35,3 @@ Also, you can test out fig files in `examples` folder. ## Learn Fig Fig has a [book](https://fig-lang.github.io/book/docs/Fig%20introduction) for learning the syntax and basic principles of fig. - -## Server-side -You can write server-side applications with FigLang, FigCli has a command called `server` That will listen to the address and port you specified, -each time a request arrives 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: - -`fig server ./test.fig --addr localhost:8080` - -### Example server-side code -Here is an example source code of using the 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 the HTTP request as `char[]` or a string. - -`test.fig`: - -``` -import server; - -export fn main (req: char[]): char[] { - let headers = "Content-Type: text/html -Connection: Closed"; - - let res = new_response("200", "OK", headers, "

Hello World

"); - - return res; -} -``` - -The `main` function must return the HTTP response as a `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.