Skip to content

Commit

Permalink
Server section moved to book
Browse files Browse the repository at this point in the history
  • Loading branch information
nyzd committed Mar 16, 2024
1 parent 5e14c8c commit 73d3972
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<h1>Hello World</h1>");
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.

0 comments on commit 73d3972

Please sign in to comment.