#1656 Dispatch scala equivalent in Fantom?

Xan Tue 27 Sep 2011

Hi,

I'm wondering with dispatch for scala. Is something equivalent to Fantom

Could I import java libraries?

Thanks in advance, Xan.

Xan Tue 27 Sep 2011

Sorry dispatch

brian Wed 28 Sep 2011

You can use Java FFI to work existing Java libraries. I am not sure what "dispatch", but at first glance just seems like an web::WebClient API.

Xan Wed 28 Sep 2011

How can I use Java FFI in Fantom?

DanielFath Wed 28 Sep 2011

Here is the doc on it: http://fantom.org/doc/docLang/JavaFFI.html

Xan Sun 2 Oct 2011

I read web::WebClient, but the documentation does not specify the headers I get frim the method "reqHeaders". What are these headers? Where do I get the headers I could consult?

Thanks a lot, Xan.

Xan Sun 2 Oct 2011

For the other hand, web::Webclient is asyncronous? That is non-blocking system? Is there anyway for getting it?

Thanks, Xan.

brian Sun 2 Oct 2011

I read web::WebClient, but the documentation does not specify the headers I get frim the method "reqHeaders". What are these headers? Where do I get the headers I could consult?

The headers are whatever you want to send to the client or whatever the server returns. I believe the only required header added by WebClient is Host which is derived from your reqUri field.

For the other hand, web::Webclient is asyncronous? That is non-blocking system?

WebClient is synchronous. You would need to wrap it in an Actor to make it asynchronous and decide how messaging would work.

Xan Mon 3 Oct 2011

But how to use reqHeaders? I need a hash of strings? It seems like I need it by documentation.

Can you give me an example of use?

Respecting to sync, how can I do that if the library is sync?

Thanks, Xan.

go4 Mon 3 Oct 2011

Xan Wed 11 Jan 2012

Is there any way to specify the charset (encoding) in getStr method?

In scala, you can do it with:

... implicit val codec = Codec(codification) val u = new java.net.URL(chain) val in = scala.io.Source.fromURL(u) ...

Thanks, Xan.

Yuri Strot Wed 11 Jan 2012

Looks like you can use client.getIn.with { charset = ... }.readAllStr

Xan Thu 12 Jan 2012

Yes, thanks a lot, ystrot.

The full code here:

using web::WebClient using sys::InStream using sys::Charset

class HelloWorld {

static Void main(Str[] args)
{
  try {

|___|___args.each {

|___|___response := WebClient(`$it`).getIn.with{charset = sys::Charset.fromStr("iso-8859-1")}.readAllStr.size
|___|___echo(response)

|___|___} |___} |___catch (Err e) { |___|___echo(e) |___} } }

(___|___ is vim tab visualization)

Login or Signup to reply.