/type-is

Infer the content-type of a request.

Primary LanguageScalaApache License 2.0Apache-2.0

TypeIs API for Scala.js

type-is - Infer the content-type of a request.

Description

Infer the content-type of a request.

Build Dependencies

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
import io.scalajs.npm.typeis.TypeIs
import scalajs.js

Http.createServer( (req, res) => {
    // req.headers.content-type = 'application/json' 
    import TypeIs._
    is(req, js.Array("json"))               // 'json'
    is(req, js.Array("html", "json"))       // 'json'
    is(req, js.Array("application/*"))      // 'application/json'
    is(req, js.Array("application/json"))   // 'application/json'
})

Artifacts and Resolvers

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

libraryDependencies += "io.scalajs.npm" %%% "type-is" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases")