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 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-federation-response

v0.0.3

Published

The Federation Response module is a predefined response structure that is used by APIs in the API-Federation Ecosystem (AFE) to serve responses that conform to the R1-Response structure as defined by AFE. This version was modified to support integration w

Downloads

4

Readme

express-federation-response (EFR)

express-federation-response is a response object created to standardize the response format of micro-services within a federation of services. This module requires a store.json file which is where all messages, directives and project scopes (form-fields, supported-langs, error-states, etc) are stored. this file can be auto-generated by notification-manager. NOTE: this module relies on the store.json file for data, it is the only required argument.

// setting up express
const express = require('express')
const app = express()
const server = require('http').createServer(app)
const port = 9000

// setting up express-federation-response

const { response } = require('express-federation-response') // include the module from your packages

const storefile = require('./store.json') // imports the store.js from your file system

app.use(response(storefile)) // adds ctx to your req object. A new response instance is created on each request.

// routes go here ...

server.listen(port, () => {
    console.log(`server running at http://localhost:${port}`)
})

example 1: EFR usage in routes

app.use((req, res) => {
    const { response } = req.ctx
    response
        .langTo('zh') // sets the response language to chinese, if this function is not called it will default to english.
        .message('invalid_token') // adds a message detail to the response.
        .message('authenticated_user', {username:'my-username'}) // adds a message template detail to the response as the first argument, and data as the second.
        .message('invalid_password')
        .payloadTo({first:'some-data', second:['some-more-data']}) // adds a payload to the response
        .statusTo(500) // sets the response status to 500, if this function is not called it will detault to the status of the first message in the reponse details. if no messages were set it will be 200. 
        .send() // is the same as calling res.status(200).json(Response)
})

The above code would yield the following response:


{
    "id": 9570,
    "isFederationResponse": true,
    "status": 500,
    "lang": "zh",
    "payload": {
        "first": "some-data",
        "second": [
            "some-more-data"
            ]
    },
    "details": [
        {
            "code": "invalid_token",
            "status": 401,
            "state": "error",
            "key": "",
            "message": "token格式有误 - ER9570."
        },
        {
            "code": "authenticated_user",
            "status": 200,
            "state": "info",
            "key": "",
            "message": "欢迎回来my-username"
        },
        {
            "code": "invalid_password",
            "status": 422,
            "state": "validation",
            "key": "password",
            "message": "密码不对"
        }
    ],
    "directives": [],
    "created": "3/11/2020, 11:19:26 AM"
    }