Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add one-import usage for sttp #125

Merged
merged 5 commits into from
Jul 19, 2018
Merged

add one-import usage for sttp #125

merged 5 commits into from
Jul 19, 2018

Conversation

lihaoyi
Copy link
Contributor

@lihaoyi lihaoyi commented Jul 18, 2018

#121

I basically moved the package object into a trait, made the package object inherit from it, and added two simpleApi objects (one on JVM, one on JS) that let you import com.softwaremill.sttp.simpleApi._ and get the normal stuff imported into scope together with a default configuration of the relevant backend (HttpUrlConnectionBackend or FetchBackend)

Seems to work:

lihaoyi sttp$ sbt core/test:console

scala> import com.softwaremill.sttp.simpleApi._
import com.softwaremill.sttp.simpleApi._

scala> sttp.get(uri"http://www.google.com").send()
res0: com.softwaremill.sttp.Id[com.softwaremill.sttp.Response[String]] =
Response(Right(<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-SG"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/logos/doodles/2018/gino-bartalis-104th-birthday-5380660112916480-law.gif" itemprop="image"><meta content="Gino Bartali&#8217;s 104th Birthday" property="twitter:title"><meta content="Gino Bartali&#8217;s 104th Birthday #GoogleDoodle" property="twitter:description"><meta content="Gino Bartali&#8217;s 104th Birthday #GoogleDoodle" property="og:description"><meta content="summary_large_image" property="twitter:card"><meta content="@GoogleDoodles" property="twitter:site"><meta content="https://www.google.com/...

let's see what CI says

@mukel
Copy link

mukel commented Jul 18, 2018

The FetchBackend is meant for browsers, it doesn't work on node. Ideally the "default" JS backend should work on both environments similar to RosHttp. But that's a story for another PR.

import scala.concurrent.duration._
import scala.language.higherKinds

trait SttpApi extends sttpExtensions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe sttpExtensions could now become SttpApiExtensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but this was the existing name so I feel changing it is kind of orthogonal to this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was for consistency, as previously these were extensions to the sttp package object. Hence the lower-case name prefix :)

@@ -0,0 +1,5 @@
package com.softwaremill.sttp

object simpleApi extends SttpApi{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would be leaning towards calling this package quick. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@adamw
Copy link
Member

adamw commented Jul 18, 2018

Thanks for the PR! I left two naming notes. Also, I think the README and docs can be updated with the new usage?

@adamw
Copy link
Member

adamw commented Jul 18, 2018

@mukel if you would know how to write a node backend, that would be great :)

@lihaoyi
Copy link
Contributor Author

lihaoyi commented Jul 19, 2018

I renamed the things to quick as you requested

@lihaoyi
Copy link
Contributor Author

lihaoyi commented Jul 19, 2018

capitalized SttpExtensions

@adamw adamw merged commit a3e42b0 into softwaremill:master Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants