Giter Site home page Giter Site logo

williamhaw / sttp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from softwaremill/sttp

0.0 1.0 0.0 2.12 MB

The Scala HTTP client you always wanted!

Home Page: https://softwaremill.com/open-source/

License: Apache License 2.0

Scala 99.66% Shell 0.34%

sttp's Introduction

sttp

Join the chat at https://gitter.im/softwaremill/sttp Build Status Maven Central

The Scala HTTP client that you always wanted!

sttp is an open-source library which provides a clean, programmer-friendly API to define HTTP requests and execute them using one of the wrapped backends, such as akka-http, async-http-client, http4s or OkHttp.

import com.softwaremill.sttp._

val sort: Option[String] = None
val query = "http language:scala"

// the `query` parameter is automatically url-encoded
// `sort` is removed, as the value is not defined
val request = sttp.get(uri"https://api.github.com/search/repositories?q=$query&sort=$sort")
  
implicit val backend = HttpURLConnectionBackend()
val response = request.send()

// response.header(...): Option[String]
println(response.header("Content-Length")) 

// response.unsafeBody: by default read into a String 
println(response.unsafeBody)                     

Documentation

sttp documentation is available at sttp.readthedocs.io.

scaladoc is available at https://www.javadoc.io

You can also take a look at the introductory blog and its follow-up.

Quickstart with Ammonite

If you are an Ammonite user, you can quickly start experimenting with sttp by copy-pasting the following:

import $ivy.`com.softwaremill.sttp::core:1.7.1`
import com.softwaremill.sttp.quick._
sttp.get(uri"http://httpbin.org/ip").send()

This brings in the sttp API and an implicit, synchronous backend.

Quickstart with sbt

Add the following dependency:

"com.softwaremill.sttp" %% "core" % "1.7.1"

Then, import:

import com.softwaremill.sttp._

Type sttp. and see where your IDE’s auto-complete gets you!

Contributing

If you have a question, or hit a problem, feel free to ask on our gitter channel!

Or, if you encounter a bug, something is unclear in the code or documentation, don’t hesitate and open an issue on GitHub.

We are also always looking for contributions and new ideas, so if you’d like to get into the project, check out the open issues, or post your own suggestions!

Testing the Scala.JS backend

Running the tests using the JS backend has some prerequisities:

Note that running the default test task will run the tests using both the JVM and JS backends. If you'd like to run the tests using only the JVM backend, execute: sbt rootJVM/test.

Building & testing the scala-native backend

By default, sttp-native will not be included in the aggregate build of the root project. To include it, define the STTP_NATIVE environmental variable before running sbt, e.g.:

STTP_NATIVE=1 sbt

You might need to install some additional libraries, see the scala native documentation site.

On MacOS, you need to: brew install llvm bdw-gc re2 libidn curl. If your system curl is older than 7.56.0, you'll need to use the updated brewl-curl when linking & compiling. To do that, create a core/native/local.sbt file, and add:

nativeCompileOptions += "-I/usr/local/opt/curl/include"
nativeLinkingOptions += "-L/usr/local/opt/curl/lib"

where the specific paths correspond to the output of the brew install curl command.

sttp's People

Contributors

adamw avatar scala-steward avatar softwaremill-ci avatar pcejrowski avatar omainegra avatar kubukoz avatar ghostbuster91 avatar aeons avatar guymers avatar amorfis avatar nitsh avatar loicdescotte avatar pm47 avatar mkubala avatar lihaoyi avatar joshlemer avatar chergey avatar darekmydlarz avatar jsw avatar mmatloka avatar szimano avatar ferada avatar n4to4 avatar matwojcik avatar intracer avatar yvoderatskyi avatar stewsquared avatar sullis avatar baccata avatar mattkohl avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.