How to use the @stoplight/prism-http.createInstance function in @stoplight/prism-http

To help you get started, we’ve selected a few @stoplight/prism-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / prism / examples / library-example / index.ts View on Github external
async function init() {
  const prism = createInstance();
  await prism.load({ path: relative(process.cwd(), process.argv[2]) });

  const server = fastify();
  server.all('*', createRequestHandler(prism));
  return server.listen(PORT);
}
github stoplightio / prism / packages / http-server / src / server.ts View on Github external
} catch (e) {
        return done(e);
      }
    }

    if (typeIs(req, ['application/x-www-form-urlencoded'])) {
      return done(null, body);
    }

    const error: Error & { status?: number } = new Error(`Unsupported media type.`);
    error.status = 415;
    Error.captureStackTrace(error);
    return done(error);
  });

  const prism = createInstance(config, components);

  const replyHandler: fastify.RequestHandler = (request, reply) => {
    const {
      req: { method, url },
      body,
      headers,
      query,
    } = request;

    const input = {
      method: (method ? method.toLowerCase() : 'get') as HttpMethod,
      url: {
        path: (url || '/').split('?')[0],
        query,
        baseUrl: query.__server,
      },