npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

funql-api

v1.2.11

Published

Build your next function based api today.

Readme

funql-api

Build your next function based api today.

This library allow you to build a function based API. Interact with the server-side with functions and promises.

Features

  • Load functions from FileSystem
  • Transform responses in the server side
  • Namespaces
  • Client-side library
  • Sockets support

Installation

npm i --save funql-api
yarn add funql-api
import funql from 'funql-api'
const funql = require('funql')

Server configuration

const app = express()
//Normal usage: call the middleware
funql.middleware(app, {
    /*defaults*/
    getMiddlewares:[],
    postMiddlewares:[],
    allowGet:false,
    allowOverwrite:false,
    attachToExpress:false,
    allowCORS: false,
    bodyParser:true, //required for POST
    api: {
        async helloWorld(name) {
            return `Hello ${name}`
        },
        backoffice:{
            getUsers(){
                return ['Juan','Paco']
            }
        }
    }
})

Load functions from folder

Basic usage

await funql.loadFunctionsFromFolder({
    path: require('path').join(process.cwd(),'functions')
})

Custom middlewares

These middlewares will act only on the functions loaded from this path. These are not express middlewares!

await funql.loadFunctionsFromFolder({
    namespace:'admin',
    path: require('path').join(process.cwd(),'functions')
    middlewares:[async function(){
//All the functions in namespace admin will invoke this middleware before running the function. If we return {err:'something'} The function will not be called and the client will receive a 200 status with the response. Useful for controlled exceptions.

return this.user.role!=='admin'?
({err:401}):true

    }]
})

Overwrite existing functions in the same path

If the function already exists, it will be overwritted.

await funql.loadFunctionsFromFolder({
    allowOverwrite:true,
    path: require('path').join(process.cwd(),'functions')
})

Load functions into namespace

await funql.loadFunctionsFromFolder({
    namespace:'backoffice',
    path: require('path').join(process.cwd(),'functions')
})

Express object binding

funql.middleware(app,{
    attachToExpress:true,
    api:{
        helloWorld(){
            return "Hello W"
        }
    }
})
console.log(app.api.helloWorld())
//Hello W

HTTP GET

Optionally, allow GET calls to interact with your functions.

funql.middleware(app,{
    allowGet:true
})

GET Middlewares

funql.middleware(app,{
    allowGet:true,
    getMiddlewares: [
        function(req, res, next) {
res.status(401).send('You are not allowed to request using GET!')
        }
    ]
})

CORS

Allow all

funql.middleware(app,{
    allowCORS:true
})

Customize allowed origins

funql.middleware(app,{
    allowCORS:['client1.domain.com','client2.domain.com']
})

Body parser

Disable body parser

In case you want to implement your own body parser.

app.use(require('body-parser').json())
funql.middleware(app,{
    bodyParser:false
})

Built-in body parser options

Give options to default express body parser.

funql.middleware(app,{
    bodyParser: {
        limit: '50mb'
    }
})

Client configuration

Basic Usage (Client)

axios.post(`SERVER_URL/funql-api`, {
    name: 'helloWorld',
    args:['Juan']
})
.then(res => {
    //Hello Juan
})
/*
server-side
function helloWorld(name){
    return `Hello ${name}`
}
*/

Feature: Namespaces

Namespaces help you to organize you a bit. You can use it for versioning!

axios.post(`SERVER_URL/funql-api`, {
    namespace:'api.v1.users',
    name: 'changePassword'
})

Feature: Transform the response in the server side

axios.post(`SERVER_URL/funql-api`, {
    namespace:'backoffice',
    name: 'helloWorld',
    args:['Juan']
    transform: function(response) {
        return response.toLowerCase()
    }.toString()
})
.then(res => {
    //juan
})

Feature: Use HTTP GET

let body = require('btoa')(JSON.stringify({
    name: 'foo'
}))
axios.get(`SERVER_URL/funql-api?body=${body}`, {
    name: 'helloWorld',
    args:['Juan']
})
.then(res => {
    //res.data equal to 'Hello Juan'
})
/*
server-side
function helloWorld(name){
    return `Hello ${name}`
}
*/

Feature: Client library

Use your functions directly. Let's abstracts the xhr operations

<script type="module">
    
import funql from 'https://cdn.jsdelivr.net/npm/[email protected]/client.js'
    
const fql = funql('http://localhost:3000')
fql('helloWorld','Juan').then(console.info)
//Hello Juan

</script>

Feature: Sockets speed

Turnon sockets globally. (socket.io)

//server    
funql.middleware({
    sockets:true
})
funql.listen(300, ()=>console.log('Listening at 3000'))
//client    
const fql = funql('http://localhost:3000',{
    connectionMode:'sockets'
})

Tests

  • Requires Node >= 13.5
  • Requires PORT 3000 available
  • npm run test

Roadmap

  • 2019 Q2: ADMIN Backoffice