https://github.com/scalajs-io/body-parser
Node.js body parsing middleware
https://github.com/scalajs-io/body-parser
body-parser express express-middleware expressjs node nodejs npm npm-package scala scalajs
Last synced: 9 months ago
JSON representation
Node.js body parsing middleware
- Host: GitHub
- URL: https://github.com/scalajs-io/body-parser
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-02-09T05:30:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:07:18.000Z (over 6 years ago)
- Last Synced: 2025-01-17T22:42:52.017Z (11 months ago)
- Topics: body-parser, express, express-middleware, expressjs, node, nodejs, npm, npm-package, scala, scalajs
- Language: Scala
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Body-parser API for Scala.js
================================
[body-parser](https://www.npmjs.com/package/body-parser) - Node.js body parsing middleware.
### Description
Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
### Build Dependencies
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```
### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```
Then you can run the tests:
```bash
$ sbt test
```
### Examples
```scala
import io.scalajs.JSON
import io.scalajs.npm.bodyparser._
import io.scalajs.npm.express.{Express, Request, Response}
val app = Express()
// parse application/x-www-form-urlencoded
app.use(BodyParser.urlencoded(new UrlEncodedBodyOptions(extended = false)))
// parse application/json
app.use(BodyParser.json())
app.use((req: Request, res: Response) => {
res.setHeader("Content-Type", "text/plain")
res.write("you posted:\n")
res.end(JSON.stringify(req.body, null, 2))
})
```
### Artifacts and Resolvers
To add the `BodyParser` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "body-parser" % "0.5.0"
```
Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```