How to do REST requests GET and POST with IRIS in Hoon Urbit?
iris-thread.hoon
/- spider
/+ strandio
=, strand=strand:spider
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=/ url=@t (need !<((unit @t) arg))
=/ =request:http [%'GET' url ~ ~]
=/ =task:iris [%request request *outbound-config:iris]
=/ =card:agent:gall [%pass /http-req %arvo %i task]
;< ~ bind:m (send-raw-card:strandio card)
;< res=(pair wire sign-arvo) bind:m take-sign-arvo:strandio
?. ?=([%iris %http-response %finished *] q.res)
(strand-fail:strand %bad-sign ~)
~& +.q.res
?~ full-file.client-response.q.res
(strand-fail:strand %no-body ~)
(pure:m !>(`@t`q.data.u.full-file.client-response.q.res))
-iris-thread 'http://example.com'
=/ url=@t (need !<((unit @t) arg))
=/ =request:http [%'GET' url ~ ~]
=/ =task:iris [%request request *outbound-config:iris]
=/ =card:agent:gall [%pass /http-req %arvo %i task]
=request:http [%'GET' "https://example.com" ~ ~]
iris-post.hoon
/- spider
/+ strandio
=, strand=strand:spider
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=/ =header-list:http ['Content-Type' 'application/json']~
=/ =request:http
=: method.request %'POST'
url.request 'https://mainnet.infura.io/v3/063b32ba31b3461ebca9646500a22df3'
header-list.request header-list
body.request
:- ~
%- '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}'
=/ =task:iris [%request request *outbound-config:iris]
=/ =card:agent:gall [%pass /http-req %arvo %i task]
;< ~ bind:m (send-raw-card:strandio card)
;< res=(pair wire sign-arvo) bind:m take-sign-arvo:strandio
?. ?=([%iris %http-response %finished *] q.res)
(strand-fail:strand %bad-sign ~)
~& +.q.res
?~ full-file.client-response.q.res
(strand-fail:strand %no-body ~)
(pure:m !>(`@t`q.data.u.full-file.client-response.q.res))
Get Block Number
curl -X POST https://mainnet.infura.io/v3/063b32ba31b3461ebca9646500a22df3 --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}'
/- spider
/+ strandio
=, strand=strand:spider
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=/ url=@t (need !<((unit @t) arg))
=/ =request:http [%'POST' url ~ ~]
=/ =task:iris [%request request *outbound-config:iris]
=/ =card:agent:gall [%pass /http-req %arvo %i task]
;< ~ bind:m (send-raw-card:strandio card)
;< res=(pair wire sign-arvo) bind:m take-sign-arvo:strandio
?. ?=([%iris %http-response %finished *] q.res)
(strand-fail:strand %bad-sign ~)
~& +.q.res
?~ full-file.client-response.q.res
(strand-fail:strand %no-body ~)
(pure:m !>(`@t`q.data.u.full-file.client-response.q.res))
POST Request
Backlinks