-
Notifications
You must be signed in to change notification settings - Fork 1
On The Client
The Get
function takes a URI and fetches the page or resource:
m←R.Get 'https://www.googleapis.com/books/v1/volumes?q=isbn:9780226320540'
NB. In all of the code samples below and on other pages, R is a reference to the Rumba API (Rumba.Core)
The result of Get is a Message object. We can examine some of its properties:
m.(StatusCode ReasonPhrase ContentLength)
200 OK 4516
and look at the content type:
m.ContentType.ContentType
application/json; charset=UTF-8
Since it is JSON, we can dig in and see the title of the book:
(⎕JSON m.Content).items.volumeInfo.title
The Road to Serfdom
The Get function is a thin cover for a set of objects and functions that give more control over the client connection:
Get←{
u←ParseURI ⍵
c←NewClient u
q←NewRequest u.Resource
c SendAndReceive q
}
The ParseURI
function takes a URI string and parses it into its various components and returns a URI object. The NewClient
method creates a Client object, which may be used to send and receive one or more messages. If NewClient is passed a URI object or string as an argument, then its Secure, Host, and Port properties default to appropriately. These properties may of course be specified later. The NewRequest method creates a new Request object. The default Method property is GET
, but may be set to POST
or any HTTP method. The SendAndReceive
function opens a connection to the server, sends the message, and closes the connection.