Nefarious Pickle Muncher

    pubsub-http-handler
    TypeScript icon, indicating that this package has built-in type declarations

    4.2.0 • Public • Published

    PubSub HTTP Handler

    Build & Deploy Total alerts LGTM Grade Maintainability

    PubSub HTTP Handler

    PubSub HTTP Handler is a simple Typescript/Javascript package that solves serving an HTTP endpoint that can consume PubSub messages. It is intended to use with Google Cloud Functions or Google Cloud Run.

    This package was built so that when creating microservices that subscribes to a PubSub-topic, we don't have to implement a server or validate the request.

    The package utilizes Fastify to serve HTTP.

    Quickstart

    ▶ yarn add pubsub-http-handler

    Example

    import { createPubSubServer, PubSubHandler } from 'pubsub-http-handler';
    
    interface MyHandler {
      hello: string;
      world: string;
    }
    
    const server = async () => {
      const handler: PubSubHandler<MyHandler> = ({ message, data }) => {
        // `message` contains attributes, data (as string), messageId
        // `data` contains a base64 decoded JSON serialized object (type is MyHandler in the example)
        // ...
      };
    
      const { listen } = await createPubSubServer(handler);
      await listen();
    };

    We also support fastify-plugin and cloud-functions. See more examples in the examples/ folder.

    Read more about configuration here or check out the API documentation

    Options

    • onError (function, default is undefined). Use to ensure that the function doesn't throw. Warning: Using this option will make the function return 204 regardless.

    • parseJson (boolean, default is true). When set to true, uses JSON.parse to parse the data sent through PubSub.

    Contributing

    We love contributions! 🙏 Bug reports and pull requests are welcome on GitHub.

    Install

    npm i pubsub-http-handler

    DownloadsWeekly Downloads

    102

    Version

    4.2.0

    License

    Apache-2.0

    Unpacked Size

    57 kB

    Total Files

    47

    Last publish

    Collaborators

    • cobraz