Coder Social home page Coder Social logo

Comments (3)

michalkalinowski- avatar michalkalinowski- commented on May 20, 2024

Replying to myself:

I did some more code reading and I've found a solution higher up the stack in Kitura repo. One can send the request and handle response using BodyParser.parse (feels a bit hacky though)

router.get("/clientRequestTest") {
  request, response, next in

  _ = Http.request("https://httpbin.org/get") {
    res in

    // unwrap the optional res
    guard let clientResponse = res else {
      Log.error("Log some error")
      return
    }

    // parse response with Kitura's BodyParser
    if let body = BodyParser.parse(clientResponse, contentType: clientResponse.headers["Content-Type"]) {
      if case .Json(let json) = body {
        Log.info("received JSON!: \(json)")
        // handle json here 
        // and send something back
        response.send(json: json)
      }
    }
  }.end()

  response.statusCode = .OK
  next()
}

from kitura-net.

shmuelk avatar shmuelk commented on May 20, 2024

I agree completely that we need a better way or perhaps a higher level way to handle communicating outward to another RESTful endpoint from within a Kitura based endpoint.

We will look into this and see what we can do (unless someone else provides a reasonable API via a PR....)

from kitura-net.

shmuelk avatar shmuelk commented on May 20, 2024

Please add any comments in our question poll in Kitura/Kitura#436

from kitura-net.

Related Issues (20)

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.