Neolithic Prancing Minotaurs

    @dck/bs-fastify

    0.2.0 • Public • Published

    bs-fastify

    🚧

    Bucklescript bindings for fastify (v2.11.0)

    Install

    yarn add @dck/bs-node @dck/bs-fastify
    

    Add it to bs-dependencies in your bsconfig.json :

    {
      "bs-dependencies": ["@dck/bs-node", "@dck/bs-fastify"]
    }

    Usage

    Basic

    open BsFastify;
    open BsNode;
    
    let app = createApp(AppOptions.make(~logger=true, ()));
    
    app->get(baseEndpoint, (_req, res) =>
      res->Response.sendObject({"test": "test"})
    );
    
    
    let schemaProperties = Js.Dict.empty();
    schemaProperties->Js.Dict.set("name", Schema.property(~type_="string"));
    
    app->postWithSchema(
           baseEndpoint,
           Schema.createBodySchema(
             ~required=[|"name"|],
             ~properties=schemaProperties,
           ),
           (req, res) => {
             let name = req->Request.body##name;
             res->Response.sendString("Hello "++ name ++ " !");
           }
      );
    
    app->listen(3333, (err, address) =>
      switch (Js.Nullable.toOption(err)) {
        | None => Js.log("Server listening on " ++ address)
        | Some(error) => Js.log(error)
      }
    );

    Middleware

    open BsFastify;
    open BsNode;
    
    let app = createApp(AppOptions.make(~logger=true, ()));
    
    app->register([%raw "require('fastify-multipart')"]);

    Usage

    open BsFastify;
    open BsNode;
    
    let app = createApp(AppOptions.make(~logger=false, ()));
    
    app->use2("/medias", serveStatic("/assets));

    Install

    npm i @dck/bs-fastify

    DownloadsWeekly Downloads

    2

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    6.35 kB

    Total Files

    5

    Last publish

    Collaborators

    • dck