Skip to content

Commit a74aa17

Browse files
Add documentation
1 parent 66674f3 commit a74aa17

13 files changed

+750
-205
lines changed

.github/document.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export FL_TITLE="Functional HTTP Server"
2+
export FL_DESCRIPTION="A simple HTTP server inspired by Express and in tune with Functional Programming principles in \
3+
JavaScript for Deno."
4+
export FL_GITHUB_URL="https://github.com/sebastienfilion/functional-http-server"
5+
export FL_DENO_URL="https://deno.land/x/functional_http_server"
6+
export FL_VERSION="v0.3.1"
7+
8+
deno run --allow-all --unstable ../@functional:generate-documentation/cli.js document \
9+
"$FL_TITLE" \
10+
"$FL_DESCRIPTION" \
11+
$FL_GITHUB_URL \
12+
$FL_DENO_URL \
13+
$FL_VERSION \
14+
./.github/readme-fragment-usage.md \
15+
./library/*.js \
16+
./.github/readme-fragment-license.md
File renamed without changes.

.github/readme-fragment-license.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Contributing
2+
3+
We appreciate your help! Please, [read the guidelines](./CONTRIBUTING.md).
4+
5+
## License
6+
7+
Copyright © 2020 - Sebastien Filion
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
12+
persons to whom the Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15+
Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

.github/readme-fragment-usage.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## Usage
2+
3+
Functional HTTP Server is optimized to write elegant and powerful point-free functions. This example uses the Ramda
4+
library - for simplification - but you should be able to use any library that implements the Fantasy-land
5+
specifications.
6+
7+
This example showcase how to create an endpoint handler for `POST /hoge` that writes to a local file and to Redis
8+
simultaneously the content of the request's body and, replies with `201`.
9+
10+
```js
11+
import Task from "https://deno.land/x/[email protected]/library/Task.js";
12+
import {
13+
decodeRaw,
14+
encodeText,
15+
evert,
16+
safeExtract
17+
} from "https://deno.land/x/[email protected]/library/utilities.js";
18+
import File from "https://deno.land/x/[email protected]/library/File.js";
19+
import Request from "https://deno.land/x/[email protected]/library/Request.js";
20+
import Response from "https://deno.land/x/[email protected]/library/Response.js";
21+
import { fetch } from "https://deno.land/x/[email protected]/library/browser_safe.js";
22+
import { writeFile } from "https://deno.land/x/[email protected]/library/fs.js";
23+
import RedisRequest from "https://deno.land/x/[email protected]/library/RedisRequest.js";
24+
import { $$rawPlaceholder } from "https://deno.land/x/[email protected]/library/Symbol.js";
25+
import { executeRedisCommandWithSession } from "https://deno.land/x/[email protected]/library/client.js";
26+
27+
import { handlers, route } from "https://deno.land/x/[email protected]/library/route.js";
28+
import startHTTPServer from "https://deno.land/x/[email protected]/library/server.js";
29+
30+
startHTTPServer(
31+
{ port: 8080 },
32+
route(
33+
handlers.post(
34+
"/hoge",
35+
compose(
36+
map(_ => Response.Created({ 'content-type': "text/plain" }, encodeText("Created!"))),
37+
converge(
38+
(...tasks) => evert(Task, tasks),
39+
[
40+
compose(
41+
executeRedisCommandWithSession({ port: 6379 }),
42+
concat(RedisRequest("SET", new Uint8Array([]), [ "hoge", $$rawPlaceholder ]))
43+
),
44+
compose(
45+
writeFile({}),
46+
concat(File.fromPath(`${Deno.cwd()}/hoge`))
47+
)
48+
]
49+
)
50+
)
51+
)
52+
)
53+
);
54+
55+
const container = await fetch(
56+
Request(
57+
{
58+
headers: {
59+
'accept': 'text/plain',
60+
'content-type': 'text/plain'
61+
},
62+
method: 'POST',
63+
url: 'http://localhost:8080/hoge'
64+
},
65+
encodeText("Hello, Hoge!")
66+
)
67+
).run()
68+
69+
const response = safeExtract("Failed to unpack the response", container);
70+
71+
assert(Response.Success.is(response));
72+
assertEquals(response.headers.status, 201);
73+
74+
server.close();
75+
```
76+
77+
## Simple HTTP server
78+
79+
The fastest way to start a HTTP server is to use the `startHTTPServer` function.
80+
The function takes two arguments; the first argument is the options, and the second is a unary
81+
function that takes a `Request` and return a `Task` of a `Response`.
82+
83+
```js
84+
import Task from "https://deno.land/x/[email protected]/library/Task.js";
85+
import Response from "https://deno.land/x/[email protected]/library/Response.js";
86+
import startHTTPServer from "https://deno.land/x/[email protected]/library/server.js";
87+
88+
startHTTPServer({ port: 8080 }, request => Task.of(Response.OK({}, request.raw)));
89+
```
90+
91+
You can test this simple server by executing it your file
92+
93+
```bash
94+
$ deno run --allow-net server.js
95+
```
96+
97+
```bash
98+
$ curl localhost:8080 -d "Hello, Hoge!"
99+
> Hello, Hoge!
100+
```

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.DS_Store
2+
.data/
3+
.docs/
4+
.dump/
5+
.idea/
6+
.nyc_output/
7+
.sass-cache/
8+
coverage/
9+
journal/
10+
node_modules/
11+
out/
12+
scratch/
13+
14+
*.db
15+
*.iml
16+
*.log
17+
*.rdb
18+
*.zip
19+
20+
.todo.md
21+
22+
dmfx
23+
.dmfx
24+
*.dmfx.js

CONTRIBUTING.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Contributor guidelines
2+
3+
## What do I need to know to help?
4+
5+
If you are looking to help to with a code contribution our project uses JavaScript to run on Deno and modern browsers.
6+
If you don't feel ready to make a code contribution yet, no problem! You can also check out
7+
[the issues](https://github.com/sebastienfilion/functional/issues).
8+
9+
Never made an open source contribution before? Wondering how contributions work in the in our project? Here's a quick
10+
rundown!
11+
12+
1. Find an issue that you are interested in addressing, or a feature that you would like to add;
13+
2. Fork the repository associated with the issue to your local GitHub organization. This means that you will have a
14+
copy of the repository under `github-username/repository-name`;
15+
3. Clone the repository to your local machine using git clone https://github.com/github-username/repository-name.git;
16+
4. Create a new branch for your fix using `git checkout -b branch-name-here`. The preferred pattern is to prefix the
17+
branch name, i.e.: `fix/[issue-number|*]`, `document/*` or, `implement/[issue-number|*]`;
18+
5. Make the appropriate changes for the issue you are trying to address, or the feature that you want to implement;
19+
6. Use git to commit your changes with a descriptive message, you can refer to
20+
[this article](https://dev.to/jacobherrington/how-to-write-useful-commit-messages-my-commit-message-template-20n9)
21+
to learn how to write a good commit message;
22+
7. Push the changes to the remote repository using git push origin branch-name-here;
23+
8. Submit a pull request to the upstream repository;
24+
9. Title the pull request with a short description of the changes made and the issue or bug number associated with
25+
your change. For example, you can title an issue like so "Add log messages #4352";
26+
10. In the description of the pull request, explain the changes that you made, any issues you think exist with the
27+
pull request you made, and any questions you have for the maintainer. It's OK if your pull request is not perfect
28+
(no pull request is), the reviewer will be able to help you fix any problems and improve it!
29+
11. Wait for the pull request to be reviewed by a maintainer;
30+
12. Make changes to the pull request if the reviewing maintainer recommends them.
31+
13. Celebrate your success after your pull request is merged!
32+
33+
## Where can I go for help?
34+
35+
If you need help, you can ask questions [on Discord](https://discord.gg/gp83e8dr).
36+
37+
## What does the Code of Conduct mean for me?
38+
39+
Our Code of Conduct means that you are responsible for treating everyone on the project with respect and courtesy
40+
regardless of their identity. If you are the victim of any inappropriate behavior or comments as described in our
41+
Code of Conduct, we are here for you and will do the best to ensure that the abuser is reprimanded appropriately,
42+
per our code.

0 commit comments

Comments
 (0)