falanteris v1.4.15
Important Note:
This is not the finished version of the README, it only covers basic and smaller features.
Basics
Falanteris is a multi-functional framework that you can use to build a REST-api or a web development framework.
It shares design aspects from Express, a more popular REST-api framework, but it combines smaller aspects from Flask as well.
To get started, we'll need our app constructor, we can require the Falanteris
function
from the package.
var Falanteris = require("falanteris").Falanteris
let app = Falanteris("0.0.0.0",undefined,"http")
The constructor requires 4 arguments:
1. Network Interface you're going to run it in.
2. Dependency ( you can simply supply it with undefined to ignore, but we'll get to this later
3. protocol, which can be either http or https
4. https credentials, which should be supplied with an object consisting of key
, and cert
property.
Adding redirections
Now that we have our app ready, time to add some redirections, using the addRedir
method fromt the app
object.
app.addRedir(<method>,<endpoint>,<handler>,<middlewares>)
- The method can be either "GET", "POST", "PUT", and "DELETE" which can be supplied either by string. If you want a specific endpoint to have multiple redirections you can supply this argument with an array like
["GET","POST"]
. - The endpoint is pretty self explanatory, but its pretty much the URL that needs to be accessed.
- the handler is a function that would be supplied with
req
, andres
variables. - middlewares is a list of functions that would be passed through by the request before entering the handler. The functions must consist of 3 parameters,
req
andres
object, as well as thenext
function.
Using URL as parameter
Often times, when developing a REST-api, this is a staple feature that is needed. Falanteris got that covered. In order to use the feature, we'll need to specify the exact location where the parameter is located using the []
square bracket.
Example:
`/login/username/password/password
Now, the parameters should be stored in the req
object, particularly in the rawParam
property of it. To get the username
you can call req.rawParam.username
to retrieve the username specified in the URL. The same can be done with password.
Queries are also stored in a similar manner. In the rawQuery
property of the req
object.
Using Middlewares
Middlewares are useful when you want to run a checking pipeline towards incoming requests. Simply create a common function that takes three parameters, req
, res
, and next
. The req
and res
object are similar to the ones you would use in your request handler. The next
parameter contains the next middleware that needs to be run. After done performing necessary actions, you can invoke the next
function to call the 'next' middleware in the pipeline.
Example:
function myMware(req, res, next){
console.log("Checked by middleware");
next();
}
You can then deploy this middleware by inserting it into the last parameter of addRedir
method in an array
app.addRedir(.., ..., ..., [myMware])
Final Notes
Now of course, you can export the whole app by using module.exports
Example:
module.exports = app
Neat Little Features
app.verbosity();
This feature would make the app verbose, displaying errors and partial information about the incoming request.app.enableMP(<number of cores>)
An API to run multi-processing. You can specify how many cores you wish to use. Of course, it also considers the number of processors your machine has.
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago