Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 3.06 KB

README.md

File metadata and controls

89 lines (64 loc) · 3.06 KB

Express API for Scala.js

express - Fast, unopinionated, minimalist web framework

Description

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

Related Packages

The following npm packages are related to Express:

Package Version Description
body-parser 1.16.0 Body parsing middleware.
cookie-parser 1.4.3 Cookie parsing with signatures
express-csv 0.6.0 express-csv provides response csv easily to express.
express-fileupload 0.0.7 Simple express file upload middleware that wraps around connect-busboy
express-ws 2.0.0 WebSocket endpoints for Express applications
multer 1.3.0 Multer is a node.js middleware for handling multipart/form-data.

Build Requirements

Build/publish the SDK locally

 $ sbt clean publish-local

Running the tests

Before running the tests the first time, you must ensure the npm packages are installed:

$ npm install

Then you can run the tests:

$ sbt test

Examples

import io.scalajs.nodejs.http.{Http, RequestOptions, ServerResponse}
import io.scalajs.nodejs._
import io.scalajs.npm.express._
import scala.concurrent.duration._

// create the Express application instance
val app = Express()

// define a port
val port = 8080

// setup the server with routes
val server = app
  .get("/", (_: Request, res: Response) => res.send("Hello GET"))
  .post("/", (_: Request, res: Response) => res.send("Hello POST"))
  .delete("/:id", (req: Request, res: Response) => res.send(s"Hello DELETE - ${req.params.get("id").orNull}"))
  .get("/list_user", (_: Request, res: Response) => res.send("Page Listing"))
  .get("/ab*de", (_: Request, res: Response) => res.send("Page Pattern Match"))
  .listen(port)

Http.get(s"http://localhost:$port/", { response: ServerResponse =>
    response.onData { chunk =>
      println(chunk.toString()) // Hello GET
    }
})

Artifacts and Resolvers

To add the Express binding to your project, add the following to your build.sbt:

libraryDependencies += "io.scalajs" %%% "express" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases")