Socket
Socket
Sign inDemoInstall

@benzene/http

Package Overview
Dependencies
3
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @benzene/http

Fast, minimal, agnostic GraphQL over HTTP


Version published
Weekly downloads
3.3K
decreased by-10.38%
Maintainers
1
Install size
45.1 kB
Created
Weekly downloads
 

Readme

Source

@benzene/http

npm CI codecov PRs Welcome

Fast and simple framework-agnostic GraphQL HTTP Server

Installation

npm i graphql @benzene/http

Usage

import { createServer } from "http";
import { Benzene, makeHandler, parseGraphQLBody } from "@benzene/http";

function readBody(request) {
  return new Promise((resolve) => {
    let body = "";
    request.on("data", (chunk) => (body += chunk));
    request.on("end", () => resolve(body));
  });
}

const GQL = new Benzene({ schema });

const graphqlHTTP = makeHandler(GQL, options);

createServer(async (req, res) => {
  const rawBody = await readBody(req);
  const result = await graphqlHTTP({
    method: req.method,
    headers: req.headers,
    body: parseGraphQLBody(rawBody, req.headers["content-type"]),
  });
  res.writeHead(result.status, result.headers);
  res.end(JSON.stringify(result.payload));
}).listen(3000);

Documentation

Documentation is available at benzene.vercel.app. Check out examples for integrations with different server libraries and tools.

Keywords

FAQs

Last updated on 13 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc