楼主: ReneeBK
1475 9

Dispatch: Scala library for accessing HTTP services [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4901份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49675 个
通用积分
56.1287
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2017-1-20 00:53:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
[color=rgb(51, 51, 51) !important]Scala library for accessing HTTP services http://dispatch.databinder.net/

本帖隐藏的内容

dispatch-master.zip (121.89 KB)







二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Accessing dispatch services Library service services library

沙发
ReneeBK 发表于 2017-1-20 00:54:18
  1. Diving in

  2. If you have sbt installed, Dispatch is two steps away. Open a shell and change to an empty or unimportant directory, then paste:

  3. echo 'libraryDependencies +=
  4.   "net.databinder.dispatch" %% "dispatch-core" % "0.11.2"' > build.sbt
  5. sbt console
  6. After “the internet” has downloaded, you’re good to go.
复制代码

藤椅
ReneeBK 发表于 2017-1-20 00:54:57
  1. Defining requests

  2. We’ll start with a very simple request.

  3. import dispatch._, Defaults._
  4. val svc = url("http://api.hostip.info/country.php")
  5. val country = Http(svc OK as.String)
  6. The above defines and initiates a request to the given host where 2xx responses are handled as a string. Since Dispatch is fully asynchronous, country represents a future of the string rather than the string itself.
复制代码

板凳
ReneeBK 发表于 2017-1-20 00:55:39
  1. Deferring action

  2. You can act on the response once it’s available with a for-expression.

  3. for (c <- country)
  4.   println(c)
  5. This for-expression applies to any successful response that is eventually produced. If no successful response is produced, nothing is printed. This is how for-expressions work in general. Consider a more familiar example:

  6. val opt: Option[String] = None
  7. for (o <- opt)
  8.   println(o)
  9. An option may or may not contain a value, just like a future may or may not produce a successful response. But while any given option already knows what it is, a future may not. So the future behaves asynchronously in for-expressions, to avoid holding up operations subsequent that do not depend on its value.
复制代码

报纸
ReneeBK 发表于 2017-1-20 00:56:14
  1. Demanding answers

  2. As with options, you can require that a future value be available at any time:

  3. val c = country()
  4. But the wise use of futures defers this operation as long as is practical, or doesn’t perform it at all. To see how, keep reading.
复制代码

地板
ReneeBK 发表于 2017-1-20 00:56:59
  1. Transformations

  2. A future is like an option that doesn’t know what it is yet; that doesn’t stop it from transforming into something else. We could transform an option of a string into an option of its length. Same goes for futures.

  3. import dispatch._, Defaults._
  4. val svc = url("http://api.hostip.info/country.php")
  5. val country = Http(svc OK as.String)
  6. val length = for (c <- country) yield c.length
  7. The length value is a future of integer.
复制代码

7
auirzxp 学生认证  发表于 2017-1-20 00:58:09
提示: 作者被禁止或删除 内容自动屏蔽

8
这里的黎明 发表于 2017-1-20 06:02:59

9
neuroexplorer 发表于 2017-1-20 07:48:00
Thanks!!!!!!!!

10
franky_sas 发表于 2017-1-20 07:59:06

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
扫码
拉您进交流群
GMT+8, 2026-2-2 12:31