Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-smithy/server-node

Package Overview
Dependencies
Maintainers
10
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-smithy/server-node

Base components for Smithy services running on NodeJS

  • 1.0.0-alpha.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
381
increased by12.06%
Maintainers
10
Weekly downloads
 
Created
Source

smithy-typescript/server-node

This package provides glue code to enable using a server sdk with NodeJS.

Usage

Example

import { createServer, IncomingMessage, ServerResponse } from "http";
import { HttpRequest } from "@aws-sdk/protocol-http";
import {
  GreetingService as __GreetingService,
  SayHelloInput,
  SayHelloOutput,
  getGreetingServiceHandler,
} from "@greeting-service/service-greeting";
import { convertEvent, convertResponse } from "@aws-smithy/server-node";
class GreetingService implements __GreetingService {
  SayHello(input: SayHelloInput, request: HttpRequest): SayHelloOutput {
    return {
      greeting: `Hello ${input.name}! How is ${input.city}?`,
    };
  }
}
const serviceHandler = getGreetingServiceHandler(new GreetingService());

const server = createServer(async function (
  req: IncomingMessage,
  res: ServerResponse<IncomingMessage> & { req: IncomingMessage }
) {
  // Convert NodeJS's http request to an HttpRequest.
  const httpRequest = convertRequest(req);

  // Call the service handler, which will route the request to the GreetingService
  // implementation and then serialize the response to an HttpResponse.
  const httpResponse = await serviceHandler.handle(httpRequest);

  // Write the HttpResponse to NodeJS http's response expected format.
  return writeResponse(httpResponse, res);
});

server.listen(3000);
console.error("Listening on port 3000");

FAQs

Package last updated on 18 Apr 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc