1.2.1 • Published 4 years ago

yoctoserver v1.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

yoctoserver

A simple HTTP server

Routes

Just do a

/*
* params for paramaters in handler function (object)
* headers for request headers in handler function (object)
*/
// path, output handler function, response headers (optional), status code (optional)
yoctoserver.path("/", () => "Hello, World!");
// or for json
yoctoserver.path("/", () => {return {wallet: "asadaf"}}, {"Cookie": "acookie=1"});

POST

By default, yoctoserver uses GET. You can change that by using yoctoserver.path_post. Usage is same.

Files

You can use file forms with yoctoserver. The usage is same as yoctoserver.path_post, but it's yoctoserver.path_file. Just add a form with enctype="multipart/form-data", add a file input, and to access:

// get a file's data (in handler function)
yoctoserver.files.formInputName.data // it's a binary string already
// get the filename
yoctoserver.files.formInputName.name

Static

All you need to do is:

// directory, prefix (optional)
yoctoserver.static("public", "/")

Listening

Just do

// port, host (optional)
yoctoserver.listen(8080);
yoctoserver.listen(8080, "0.0.0.0");
1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago