Skip to content

scalajs-io/request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Request API for Scala.js

request - A Simplified HTTP request client.

Description

Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.

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

Request can perform HTTP requests via callbacks:

import io.scalajs.JSON
import io.scalajs.nodejs.Assert
import io.scalajs.npm.request._

Request("http://www.google.com", { (error, response, body) => 
    Assert.equal(error, null, JSON.stringify(error))
    Assert.equal(response.statusCode, 200, response.statusMessage)
})

Request can perform streaming HTTP requests:

import io.scalajs.nodejs.Assert
import io.scalajs.nodejs.http.IncomingMessage
import io.scalajs.npm.request._

Request
    .get("http://google.com/img.png")
    .onResponse { response  => 
        Assert.equal(response.statusCode, 200, response.statusMessage)
        Assert.equal(response.headers.get("content-type").orNull, "image/png", response.headers.get("content-type").orNull)
    }
    .pipe(Request.put("http://mysite.com/img.png"))

Artifacts and Resolvers

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

libraryDependencies += "io.scalajs.npm" %%% "request" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases") 

Releases

No releases published

Packages

No packages published

Languages