Loading ...
Sorry, an error occurred while loading the content.

HttpClient usage

Expand Messages
  • debelyoo
    Hello, I m very new to blueeyes, and I m trying to use the HttpClient in my service. I read the documentation about the HttpClient ( consumption paragraph),
    Message 1 of 5 , Oct 21, 2011
    • 0 Attachment
      Hello,

      I'm very new to blueeyes, and I'm trying to use the HttpClient in my service.
      I read the documentation about the HttpClient ("consumption" paragraph), but I can't figure out how to use the client reference.

      the doc says:
      Given a reference to client, you could perform a simple HTTP GET on the path "/foo" with the following code:

      val responseFuture = client.get("http://myservice.com/foo")
      responseFuture map {response => response.content.get}

      In this code, is "client" a combinator ?
      Could you advise me on how to use the HttpClient in a service like the following:

      val dispatchService = service("dispatch", "0.1") { context =>
      startup {
      ().future
      } ->
      request {
      path("/api/v1") {
      produce(application/json) {
      path("/get/node/"+'nid) {
      get {
      request: HttpRequest[ByteChunk] => {
      resp = client.get("http://myservice.com/foo")
      Future.sync(HttpResponse[String](content = Some(resp)))
      }
      }
      }
      }
      }
      } ->
      shutdown {
      ().future
      }

      Best,
      Jean
    • John A. De Goes
      Hi Jean, You need to get an instance of HttpClient. There s a netty-based implementation that you can use. Once you have the client, you can use it in the
      Message 2 of 5 , Nov 1, 2011
      • 0 Attachment

        Hi Jean,

        You need to get an instance of HttpClient. There's a netty-based implementation that you can use. Once you have the client, you can use it in the fashion outlined in your post.
        -- 
        John A. De Goes
        CEO / CTO
        303-921-5784 - @jdegoes

        ReportGrid, Inc - http://reportgrid.com






        On Oct 21, 2011, at 5:36 AM, debelyoo wrote:

         

        Hello,

        I'm very new to blueeyes, and I'm trying to use the HttpClient in my service.
        I read the documentation about the HttpClient ("consumption" paragraph), but I can't figure out how to use the client reference.

        the doc says:
        Given a reference to client, you could perform a simple HTTP GET on the path "/foo" with the following code:

        val responseFuture = client.get("http://myservice.com/foo")
        responseFuture map {response => response.content.get}

        In this code, is "client" a combinator ?
        Could you advise me on how to use the HttpClient in a service like the following:

        val dispatchService = service("dispatch", "0.1") { context =>
        startup {
        ().future
        } ->
        request {
        path("/api/v1") {
        produce(application/json) {
        path("/get/node/"+'nid) {
        get {
        request: HttpRequest[ByteChunk] => {
        resp = client.get("http://myservice.com/foo")
        Future.sync(HttpResponse[String](content = Some(resp)))
        }
        }
        }
        }
        }
        } ->
        shutdown {
        ().future
        }

        Best,
        Jean


      • Jeff Simpson
        Hi, You need to mixin the blueeyes.core.service.ConfigurableHttpClient trait. The upside is in the test scenario it will use a mock you can define in your
        Message 3 of 5 , Nov 1, 2011
        • 0 Attachment
          Hi,

          You need to mixin the blueeyes.core.service.ConfigurableHttpClient trait.  The upside is in the test scenario it will use a mock you can define in your Specs.

          Cheers,
          -Jeff

          On 10/21/2011 05:36 AM, debelyoo wrote:
           

          Hello,

          I'm very new to blueeyes, and I'm trying to use the HttpClient in my service.
          I read the documentation about the HttpClient ("consumption" paragraph), but I can't figure out how to use the client reference.

          the doc says:
          Given a reference to client, you could perform a simple HTTP GET on the path "/foo" with the following code:

          val responseFuture = client.get("http://myservice.com/foo")
          responseFuture map {response => response.content.get}

          In this code, is "client" a combinator ?
          Could you advise me on how to use the HttpClient in a service like the following:

          val dispatchService = service("dispatch", "0.1") { context =>
          startup {
          ().future
          } ->
          request {
          path("/api/v1") {
          produce(application/json) {
          path("/get/node/"+'nid) {
          get {
          request: HttpRequest[ByteChunk] => {
          resp = client.get("http://myservice.com/foo")
          Future.sync(HttpResponse[String](content = Some(resp)))
          }
          }
          }
          }
          }
          } ->
          shutdown {
          ().future
          }

          Best,
          Jean

        • mlagutko
          You have 2 options: 1. Create http client: val httpClient = new HttpClientXLightWeb() 2. You can use ConfigurableHttpClient: trait MyService extends
          Message 4 of 5 , Nov 2, 2011
          • 0 Attachment
            You have 2 options:
            1. Create http client:
            val httpClient = new HttpClientXLightWeb()
            2. You can use ConfigurableHttpClient:
            trait MyService extends BlueEyesServiceBuilder with HttpRequestCombinators with ConfigurableHttpClient{
            ..
            }

            then you can get client by using "httpClient" declared in ConfigurableHttpClient.

            Keep in mind that if you use ConfigurableHttpClient then "mockClient" is used in tests. You should define "mockClient" in test:

            object MySpec extends BlueEyesServiceSpecification{
            override val mockServer =
            path("/foo") {
            get { request: HttpRequest[ByteChunk] =>
            HttpResponse[JValue](status = OK).future
            }
            }
            }
            }
            // tests
            ...
            }

            So your service will look like:

            val dispatchService = service("dispatch", "0.1") { context =>
            startup {
            ().future
            } ->
            request {
            path("/api/v1") {
            get { request: HttpRequest[ByteChunk] =>
            httpClient.get("http://myservice.com/foo")
            }
            }
            }
            } ->
            shutdown {
            ().future
            }


            --- In blueeyes-web@yahoogroups.com, "debelyoo" <jean.rossier@...> wrote:
            >
            > Hello,
            >
            > I'm very new to blueeyes, and I'm trying to use the HttpClient in my service.
            > I read the documentation about the HttpClient ("consumption" paragraph), but I can't figure out how to use the client reference.
            >
            > the doc says:
            > Given a reference to client, you could perform a simple HTTP GET on the path "/foo" with the following code:
            >
            > val responseFuture = client.get("http://myservice.com/foo")
            > responseFuture map {response => response.content.get}
            >
            > In this code, is "client" a combinator ?
            > Could you advise me on how to use the HttpClient in a service like the following:
            >
            > val dispatchService = service("dispatch", "0.1") { context =>
            > startup {
            > ().future
            > } ->
            > request {
            > path("/api/v1") {
            > produce(application/json) {
            > path("/get/node/"+'nid) {
            > get {
            > request: HttpRequest[ByteChunk] => {
            > resp = client.get("http://myservice.com/foo")
            > Future.sync(HttpResponse[String](content = Some(resp)))
            > }
            > }
            > }
            > }
            > }
            > } ->
            > shutdown {
            > ().future
            > }
            >
            > Best,
            > Jean
            >
          • debelyoo
            Thanks a lot mlagutko ! I was trying to mixin the wrong trait... I chose the second option you mentioned and it works great. Best, Jean
            Message 5 of 5 , Nov 2, 2011
            • 0 Attachment
              Thanks a lot mlagutko !
              I was trying to mixin the wrong trait... I chose the second option you mentioned and it works great.

              Best,
              Jean

              --- In blueeyes-web@yahoogroups.com, "mlagutko" <mlagutko@...> wrote:
              >
              > You have 2 options:
              > 1. Create http client:
              > val httpClient = new HttpClientXLightWeb()
              > 2. You can use ConfigurableHttpClient:
              > trait MyService extends BlueEyesServiceBuilder with HttpRequestCombinators with ConfigurableHttpClient{
              > ..
              > }
              >
              > then you can get client by using "httpClient" declared in ConfigurableHttpClient.
              >
              > Keep in mind that if you use ConfigurableHttpClient then "mockClient" is used in tests. You should define "mockClient" in test:
              >
              > object MySpec extends BlueEyesServiceSpecification{
              > override val mockServer =
              > path("/foo") {
              > get { request: HttpRequest[ByteChunk] =>
              > HttpResponse[JValue](status = OK).future
              > }
              > }
              > }
              > }
              > // tests
              > ...
              > }
              >
              > So your service will look like:
              >
              > val dispatchService = service("dispatch", "0.1") { context =>
              > startup {
              > ().future
              > } ->
              > request {
              > path("/api/v1") {
              > get { request: HttpRequest[ByteChunk] =>
              > httpClient.get("http://myservice.com/foo")
              > }
              > }
              > }
              > } ->
              > shutdown {
              > ().future
              > }
              >
              >
              > --- In blueeyes-web@yahoogroups.com, "debelyoo" <jean.rossier@> wrote:
              > >
              > > Hello,
              > >
              > > I'm very new to blueeyes, and I'm trying to use the HttpClient in my service.
              > > I read the documentation about the HttpClient ("consumption" paragraph), but I can't figure out how to use the client reference.
              > >
              > > the doc says:
              > > Given a reference to client, you could perform a simple HTTP GET on the path "/foo" with the following code:
              > >
              > > val responseFuture = client.get("http://myservice.com/foo")
              > > responseFuture map {response => response.content.get}
              > >
              > > In this code, is "client" a combinator ?
              > > Could you advise me on how to use the HttpClient in a service like the following:
              > >
              > > val dispatchService = service("dispatch", "0.1") { context =>
              > > startup {
              > > ().future
              > > } ->
              > > request {
              > > path("/api/v1") {
              > > produce(application/json) {
              > > path("/get/node/"+'nid) {
              > > get {
              > > request: HttpRequest[ByteChunk] => {
              > > resp = client.get("http://myservice.com/foo")
              > > Future.sync(HttpResponse[String](content = Some(resp)))
              > > }
              > > }
              > > }
              > > }
              > > }
              > > } ->
              > > shutdown {
              > > ().future
              > > }
              > >
              > > Best,
              > > Jean
              > >
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.