GithubHelp home page GithubHelp logo

express-accept-events-temp's Introduction

Express-Accept-Events

A Connect/Express style middleware to parse the Accept-Events header field specified in Per Resource Events.

Installation

Install Express-Accept-Events using your favourite package manager.

npm|pnpm|yarn add express-accept-events

Usage

In case one is using an Express server:

import AcceptEvents from "express-accept-events";
const app = express();
app.use(acceptEvents);

The middleware populates req.acceptEvents with a list of notification protocols and their corresponding parameters (sorted by the value of a q parameter, if provided) in GET and POST requests. For Example, the following HTTP request:

GET /notifications HTTP/1.1
Host: example.com
Accept: text/plain
Accept-Events: "prep"; accept="message/rfc822"; q=0.9, "solid"; type="WebSocket2023"

with the GET handler, so specified:

app.get('/foo', (req, res) => {
  console.log(req.acceptEvents);
});

will result in the output:

[
  [ "solid", Map(1) { "type" => "WebSocket2023" } ]
  [ "prep", Map(2) { "accept" => "message/rfc822", "q" => 0.9 } ]
]

Errors

In case the middleware fails to parse the Accept-Events header field, the req.acceptEvents property is not created.

Copyright and License

Copyright © 2024, Rahul Gupta

The source code in this repository is released under the Mozilla Public License v2.0.

express-accept-events-temp's People

Contributors

cxres avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.