项目作者: scalajs-io

项目描述 :
Simplified HTTP request client.
高级语言: Scala
项目地址: git://github.com/scalajs-io/request.git
创建时间: 2017-02-06T02:13:33Z
项目社区:https://github.com/scalajs-io/request

开源协议:

下载


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

  1. $ sbt clean publish-local

Running the tests

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

  1. $ npm install

Then you can run the tests:

  1. $ sbt test

Examples

Request can perform HTTP requests via callbacks:

  1. import io.scalajs.JSON
  2. import io.scalajs.nodejs.Assert
  3. import io.scalajs.npm.request._
  4. Request("http://www.google.com", { (error, response, body) =>
  5. Assert.equal(error, null, JSON.stringify(error))
  6. Assert.equal(response.statusCode, 200, response.statusMessage)
  7. })

Request can perform streaming HTTP requests:

  1. import io.scalajs.nodejs.Assert
  2. import io.scalajs.nodejs.http.IncomingMessage
  3. import io.scalajs.npm.request._
  4. Request
  5. .get("http://google.com/img.png")
  6. .onResponse { response =>
  7. Assert.equal(response.statusCode, 200, response.statusMessage)
  8. Assert.equal(response.headers.get("content-type").orNull, "image/png", response.headers.get("content-type").orNull)
  9. }
  10. .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:

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

Optionally, you may add the Sonatype Repository resolver:

  1. resolvers += Resolver.sonatypeRepo("releases")