![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A minimal REST server that deals solely with JSON payloads that automatically handles CORS requests and limits the size of a POST bodies.
npm install -S take-five
const five = require('take-five')
const server = five()
server.get('/', (req, res) => res.send('Hello, world'))
server.post('/', (req, res) => res.send(req.body))
server.listen(3000)
curl -X GET localhost:3000
Hello, world
curl -X POST localhost:3000 -H 'content-type: application/json' -d '{"hello": "world"}'
{"hello": "world"}
five(opts?:object):object
Create and return a new HTTP server object.
opts.maxPost?:number
: the max size for a payload. Default: 512kbopts.cors?:object
opts.cors.headers?:array(string)
: an array of headers to accept besides the default. Default: Content-Type
, Accept
, X-Requested-With
opts.cors.origin?:string
: What origin(s) are accepted. Deafult: *
opts.cors.credentials?:boolean
: Allow or deny credentials. Default: true
opts.cores.methods?array(string)
: an array of methods to accept besides the default. Default: PUT
, POST
, DELETE
, GET
, OPTIONS
Five#use(middleware:function)
Add a new middleware to the stack. Middleware will be processed in the order in which they are added, which means they will be run after the built-in middleware.
middleware(request:object, response:object, next:function):function
-You must either call next
or send data to the client when you are finshed.Since the middleware signature is the same express/restify, you might be able to use existing middleware with take-five, but ymmv.
Five#router(namespace:string):object
Namespace routes. All routes defined off this router will be prefixed with the supplied namespace. The methods have the same signature as the router provided.
Five#get(route:string, handler:(function|array(function)))
Five#post(route:string, handler:(function|array(function)))
Five#put(route:string, handler:(function|array(function)))
Five#delete(route:string, handler:(function|array(function)))
Add a new route to the server. Routes may be added after the server has been started. You can supply either a single function or an array of functions to call. The array will be traversed in the order it is supplied
route:string
A wayfarer route definition.handler(request:object, response:object, next:function):function
: The handler for this route.Since this is an augmented instance of http.Server all methods and properties are available on this as well.
request:object
The http.IncomingMessage
object extended with:
params?:object
: query parameters from the URL (if any)urlParams?:object
: Named parameters from the route definition as provided by wayfarerbody?:object
: The parsed JSON body available on POST requestsresponse:object
The http.ServerResponse
object augmented with two additional methods. The defaults for sending messages are
content-type: application/json
and statusCode: 200
. The header may be overridden by
calling res.header
. The statusCode can be provided when calling the send
method.
send(statusCode?:number, body?:(string|object)):function
: Send a response.err(statusCode?:number, message?:string):function
: Send an error. If no status code is provided it will default to a 500 error. If no message is provided, it will use the default message for that status code. The message will be wrapped in a JSON object under the key message
next:function
If you are done processing the request, but you want a later handler to be able to modify the response, call next. This will invoke the next handler in the stack. If there are no more handlers left, it will call res.end()
and send the response as is. If you want to immediately send the response, you can call res.end
, res.send
or res.err
directly.
Probably not, but restify
, hapi
and express
are all over-kill on the types of services I'm building for the most part.
application/json
payloads, and doesn't need the cruft associated with other payload types.application/json
as well, but allow it be override-able if neededI found that the other three projects aim to support way more than this, which means supporting these features involves jumping through hoops or installing a ton of various other packages.
There are some scripts used for the (extremely reductive) benchmarking in /benchmark
. Using my Core-i7, I get the following data using wrk -t12 -c400 -d30s http://localhost:3000/test
. You might see different results. As with all benchmarks, these are likely indicative of nothing!
take-five: Requests/sec: 20296.63
express: Requests/sec: 10974.18
restify: Requests/sec: 9201.09
Copyright © 2016 Scripto LLC, Todd Kennedy. Reuse permitted under the Apache-2.0 license
Version 1.3.1
.pipe(res)
FAQs
Very minimal JSON-REST server
The npm package take-five receives a total of 24 weekly downloads. As such, take-five popularity was classified as not popular.
We found that take-five demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.