ORDS

Let’s talk about ORDS II

This post is part of a series that starts with this post.

Now that we have a restenabled view and we can get data from ut with a basic cURL call, let’s look at more ways to make that call and view the response.

But before those calls, lets look at what data we actually get from the REST-call. If we format the output from the cURL-call it looks something like this.

{"items":[......]
,"hasMore":true
,"limit":25
,"offset":0
,"count":25
,"links":
  [{"rel":"self".      ,"href":"https://.../ords/rest_demo_schema/vw_rest_svc/"}
  ,{"rel":"describedby","href":"https://.../ords/rest_demo_schema/metadata-catalog/vw_rest_svc/"}
  ,{"rel":"first".     ,"href":"https://.../ords/rest_demo_schema/vw_rest_svc/"}
  ,{"rel":"next".      ,"href":"https://.../ords/rest_demo_schema/vw_rest_svc/?offset=25"}
  ]
}

Items is where the arrays of rows returned is kept. I cut out all of that out for brevity. hasMore shows if I can read more data from the service. Limit how much data was requested, offset if data was skipped over before reading and count how many was actually returned. Offset may need a bit more explanation. IF you make a request and then you ask for the next set of 25, then offset will be 25 top show that the requested data starts at row 26. We’ll see that in action later.

Links are misc links to the data. Without hyperlinks in a response, the API is not REST. That is not me saying that, it is how REST is defined.

if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period.

Roy T. Fielding

Who is he and why does he has a say in what is REST you may ask. He is the primary architect of the Hypertext Transfer Protocol (HTTP/1.1), coauthor of the Internet standards for HTTP and Uniform Resource Identifiers (URI), and a founder of several open source software projects (including the Apache HTTP Server Project that produces the software running most Web servers). On top of that he write the distention that established REST. This part is often referred to as HATEOAS. Further reading about that is just a google-search away.

Back to this from that academic tangent. The links will give you a link to the data returned here, next page, metadata about the service, next set of rows, the first set of rows. If you follow the next, link the result will also have a link for previous set of rows.

With the look at what the response contains out of the way, let’s look at a few more ways to access it.

Let’s begin with letting python format the output for us.

curl https://.../ords/rest_demo_schema/vw_rest_svc/| python3 -m json.tool

That makes the response much more readable, but of course takes up much more space hight-wise. Still, to read and understand it you need something other than the raw response.

Now let’s take the same URL and put it into a web-browser.

If your web browser is set up to format json you will get a response similar to the python one. The links are even active links. Click on next and you get to see the next set of 25 rows. For this tow work you may need an extension in you web-browser. I have JSON Formatter for Chrome. Search for it for your web browser and you will get several to chose from.

In the next post we will take what we did in this and set up in the database to achieve the same with SQL and PL/SQL.

Leave a Comment

Your email address will not be published. Required fields are marked *

*