Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/figlang/fig
Browse files Browse the repository at this point in the history
  • Loading branch information
nyzd committed Feb 5, 2024
2 parents e8b0471 + e49d7dc commit 428589a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,27 @@ 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.

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 428589a

Please sign in to comment.