All Projects → emctague → serville

emctague / serville

Licence: MIT License
Serville, the fast and easy HTTP API library for NodeJS.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to serville

go-oryx-lib
The public multiple media library for https://github.com/ossrs/go-oryx.
Stars: ✭ 98 (+216.13%)
Mutual labels:  http-server
toyhttpd
I/O 模型练手代码,分别使用阻塞式 I/O、select、poll 和 epoll 和 Java NIO 实现了简单的 HTTP Server
Stars: ✭ 43 (+38.71%)
Mutual labels:  http-server
oxen-storage-server
Storage server for Oxen Service Nodes
Stars: ✭ 19 (-38.71%)
Mutual labels:  http-server
eephttpd
Serving simple static sites directly to i2p via the SAM API. (Also part of https://github.com/eyedeekay/sam-forwarder)
Stars: ✭ 15 (-51.61%)
Mutual labels:  http-server
restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 380 (+1125.81%)
Mutual labels:  http-server
kog
🌶 A simple Kotlin web framework inspired by Clojure's Ring.
Stars: ✭ 41 (+32.26%)
Mutual labels:  http-server
nhttp
An Simple http framework for Deno, Deno Deploy and Cloudflare Workers. so hot 🚀
Stars: ✭ 26 (-16.13%)
Mutual labels:  http-server
WebRelay
A netcat-like utility for windows for transferring files and streams over HTTP with support for relaying through a remote host (via websocket), a webclient, and a shell extension. PRs welcome!
Stars: ✭ 29 (-6.45%)
Mutual labels:  http-server
yarx
An awesome reverse engine for xray poc. | 一个自动化根据 xray poc 生成对应 server 的工具
Stars: ✭ 229 (+638.71%)
Mutual labels:  http-server
node-jsonrpc2
JSON-RPC 2.0 server and client library, with HTTP (with Websocket support) and TCP endpoints
Stars: ✭ 103 (+232.26%)
Mutual labels:  http-server
fs-over-http
A filesystem interface over http, with extras and docker support
Stars: ✭ 14 (-54.84%)
Mutual labels:  http-server
node-slack-events-api
Slack Events API for Node
Stars: ✭ 93 (+200%)
Mutual labels:  http-server
Swiftly
Swiftly is an easy to use Qt/C++ web framework
Stars: ✭ 20 (-35.48%)
Mutual labels:  http-server
quickserv
Dangerously user-friendly web server for quick prototyping and hackathons
Stars: ✭ 275 (+787.1%)
Mutual labels:  http-server
finch-demo
Introduction to Finch, a lightweight HTTP server library based on Twitter's Finagle.
Stars: ✭ 19 (-38.71%)
Mutual labels:  http-server
shivneri
Component based MVC web framework based on fort architecture targeting good code structures, modularity & performance.
Stars: ✭ 21 (-32.26%)
Mutual labels:  http-server
cs
开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单
Stars: ✭ 19 (-38.71%)
Mutual labels:  http-server
EthernetWebServer
This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21/SAMD51, nRF52, STM32, RP2040-based, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Coexisting now with `ESP32 WebServer` and…
Stars: ✭ 118 (+280.65%)
Mutual labels:  http-server
Kvpbase
Scalable, simple RESTful object storage platform, written in C#
Stars: ✭ 43 (+38.71%)
Mutual labels:  http-server
lazurite
A simple http server.
Stars: ✭ 17 (-45.16%)
Mutual labels:  http-server

Serville


Travis npm MIT license issues Gitter

Serville is a fast, tiny, and opinionated HTTP library for NodeJS.

Serville is perfect for your REST API - it serves up JSON, and it does it well! It takes just minutes to set it up and give it a whirl.

Set It Up:

npm i --save serville
const app = require('serville')();
app.listen('8080');

app.at('/', (q) => ({ message: "Hello!" }));
// GET localhost:8080/
// => { "message": "Hello!" }

URL Parameters:

URL parameters can be specified by putting a colon before their name in the path. Their values will show up later in the params property.

app.at('/say/:text', (q) => ({ text: q.params.text }));
// GET localhost:8080/say/hello
// => { "text": "hello" }

Optional Trailing Slash:

Want to allow an optional trailing slash at the end of a URL? Add a question mark after it to make it optional!

app.at('/either/way/?', (q) => ({ message: "Hey there! "}));
// GET localhost:8080/either/way
// => { "message": "Hey there!" }
// GET localhost:8080/either/way/
// => { "message": "Hey there!" }

Returning Promises:

Instead of returning an object, you can also return a promise. This is useful for asynchronous operations.

app.at('/delay/:secs', (q) => {
  return new Promise((res) => {
    setTimeout(() => {
      resolve({ result: "DONE" });
    }, q.params.secs * 1000);
  })
});
// GET localhost:8080/delay/10
// (10 second delay)
// => { "result": "done" }

GET and POST queries:

GET and POST query data is stored in the query property.

app.at('/echo', (q) => ({ text: q.query.text }));
// GET localhost:8080/echo?text=Hello!
// => { "text": "Hello!" }
// POST localhost:8080/echo
// POST body: text=Hello!
// => { "text": "Hello!" }

Regular Expression Matching:

You can also match paths as regular expressions! The match property will contain the results of running RegExp.match(path) with your regex.

app.at(/^\/my-name-is-(.+)$/, (q) => (
  { message: `Hello, ${q.match[1]}!` }
));
// GET localhost:8080/my-name-is-Patricia
// => { "message": "Hello, Patricia!" }

Differentiating request types:

The get, post, put, and delete functions can be used to add bindings for specific request methods.

app.get('/method', () => ({ message: 'GET request!' }));
app.post('/method', () => ({ message: 'POST request!' }));
// GET localhost:8080/method
// => { "message": "GET request!" }
// POST localhost:8080/method
// => { "message": "POST request!" }

You can also specify several methods as a third array argument to at.

app.at('/method', () => ({message: 'PUT or DELETE request!'}), ['PUT', 'DELETE']);
// PUT localhost:8080/method
// => { "message": "PUT or DELETE request!" }
// DELETE localhost:8080/method
// => { "message": "PUT or DELETE request!" }

By default, all possible methods will be accepted:

app.at('/method', () => ({message: 'Something Else!'}));
// TRACE localhost:8080/method
// => { "message": "Something Else!" }

HTTP Request Headers:

The HTTP request headers are present in the headers property.

app.at('/agent', (q) => ({ agent: q.headers['user-agent'] }));

Handling Node HTTP Server Errors:

Sometimes, node encounters HTTP errors. Use catch to add a binding for when these errors occur.

app.catch((err, socket) => {
  socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});

Notes

  • The NPM package does not include the project sources or certain files from the repository. This is to save space. If you want to save even more space, simply download serville.js and put it in your project instead. It's minified!

  • Serville doesn't yet have full code-coverage unit testing and there may be some quirks or bugs. If you find anything, please submit an issue!

Contributing

Fork and clone this repository to get started, then run npm i to install dev dependencies. There's no formal contribution procedure (yet), feel free to submit PRs and issues as you see fit. Contributions are very much welcomed!

Just note that you can't work directly on the master branch, as it is protected. We recommend editing code on your own branch, then merging into develop. You may only merge with master after your PR is approved and continuous integration checks pass.

The source code for the library is in lib/serville.js. Modify the testing script in lib/test.js to try out your changes and new features. You can run these tests with npm run dev.

To build the current version of the server to serville.js, simply run npm run build.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].