artanis
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: http-request in a controller- is it possible?


From: Jaft
Subject: Re: http-request in a controller- is it possible?
Date: Mon, 7 Dec 2020 06:42:39 +0000 (UTC)

Ahh, that's right; sorry about that. I remember, now.

So I updated the example with the corrected code and calling the endpoint did work; I can see art noting that it's being called.

(get "/test-endpoint" #:mime #t
  (lambda (rc)
    (display "Something here")
    (newline)

    (let ([port (open-socket-for-uri "http://127.0.0.1:3000/other-endpoint")])
      (fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFD 0)))

      (receive (headers body)
          (http-get "http://127.0.0.1:3000/other-endpoint" #:port port)
        (display "JSON: ")
        (display (utf8->string body))
        (newline)))

    (:mime rc '(("this is the " . "first endpoint we call")))))

And that did work.

Interestingly, another endpoint I was working with with a similar setup (inspiration for the test example) didn't; like, it was able to call the other endpoint it needed to successfully but then the original endpoint never resumes, after making the http-get call.

The only other major difference I can think of is that the endpoint which is called then calls a function in a module in the lib directory and that function is what makes the http-get call to the other endpoint.

I don't want to bog down the mailing list with debugging my custom code but I mention it in case it helps as something to look out for or the like.

Our example here, though, definitely works and I was able to run against it consistently. Thanks (as always) for all the help; it's always super appreciated.

Jonathan
On Sunday, December 6, 2020, 11:23:48 PM CST, Nala Ginrut <mulei@gnu.org> wrote:



Hi Jaft!

Jaft writes:

>  Gotcha; so something like?
> (get "/test-endpoint" #:mime #t  (lambda (rc)    (display "Something here")    (newline)
>    (break-task)    (receive (headers body)        (http-get "http://127.0.0.1:3000/other-endpoint")      (display "JSON: ")      (display (utf8->string body))      (newline))
>    (:mime rc '(("this is the " . "first endpoint we call")))))
> Unfortunately, I get the same result of
> Enter ragnarok scheduler!Save current task #<ragnarok-client treasure: (#<input-output: socket 34> . #(2 2130706433 60016))>!Add new task #<input-output: socket 34> == #<input-output: socket 34>Save okServe one donemain-loop again
> outputted by art, as before.
> Or is that because http-get freezes and hangs, even with Ragnarok, currently?
> Jonathan    On Sunday, December 6, 2020, 12:12:31 AM CST, Nala Ginrut <mulei@gnu.org> wrote:

You don't have to call (break-task) here manually, since Ragnarok will
schedule it for you. As I mentioned in previous mails, there should be
client API in Artanis in the future, for now, you have to set the port
to non-blocking by yourself.

--------------------------cut--------------------------------------
(define port (open-socket-for-uri "http://localhost:3000/123"))
(fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFL 0)))
(http-get "http://......." #:port port)

--------------------------end--------------------------------------




--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
Fingerprint F53B 4C56 95B5 E4D5 6093 4324 8469 6772 846A 0058

reply via email to

[Prev in Thread] Current Thread [Next in Thread]