What is ORDS?
This article provides an overview of the JSON functionality available when using an Oracle database, along with links to relevant articles.
Related articles.
In today's development world relational databases are considered a legacy technology by many. PL/SQL is also considered a legacy language. With that in mind, how do we as Oracle DBAs and PL/SQL developers stay relevant? One way is to make sure everything we do is easily accessible.
I'm a fan of the smart-database model . For years I've been telling people to publish their PL/SQL APIs as web services. In the past I was mostly preaching XML (REST and SOAP). With the popularity of JavaScript in the development world, RESTful web services and JSON are everywhere. Fortunately Oracle gives us lots of tools to present SQL and PL/SQL as RESTful web services.
Here is a quote.
> "JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
"JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
"JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
JSON data is made up of name/value pairs, where the value can be a JSON object, JSON array, number, string, boolean or null.
A JSON object is made up of one-to-many name/value pairs separated by commas and placed inside curly braces. The name/value pairs don't have to be of the same types.
A JSON array is a comma-separated list of objects inside square brackets. The objects don't have to be of the same type.
It's really easy to convert JSON to a JavaScript object and vice-versa.
Even if you don’t use JavaScript, JSON is still useful. You can think of JSON as "skinny XML". Typically the JSON representation of data requires less characters than the XML equivalent, whether you use tag-based or attribute-based XML. The following example of tag-based XML requires about 768 characters when minified. Minification is the removal of all unnecessary characters, including unnecessary white spaces and new lines.
The same data represented as attribute-based XML requires about 537 characters when minified.
The JSON representation of the data requires just 470 characters when minified.
Anything that reduces the number of characters being sent, whilst retaining readability, is interesting where data transfers are concerned, which is why JSON has become a strong favourite when coding web services.
REST stands for Representational State Transfer. There are many long and boring discussions about what it is or is not. If you are interested, you can start reading about it here . Instead of that, let's cut to the chase by focussing on JSON-based RESTful web services using HTTP.
To put it simply, we should have a URI which represents a specific resource. Assuming we want to interact with data about employees, we might have something like the following.
All interactions with employees will be via this same URI. We identify what we want to do using the HTTP method.
- GET : This is for returning information about a resource. Depending on the parameters used this could return all records, a specific subset of records, or a single record. The important point is a GET should not be used to alter data. In simple examples a GET is often mapped to a SELECT statement.
- POST : This is used to create a new resource. So we might use a POST to create a new employee. In simple examples a POST is often mapped to an INSERT statement.
- PUT : This is used to amend an existing resource. So we might use a PUT to amend an existing employee. In simple examples a PUT is often mapped to an UPDATE statement. In many cases, a put will amend a resource if it is present, or create it if it isn't. I personally don't like this functionality, but that is just my opinion.
- DELETE : This is used to remove an existing resource. In simple examples a DELETE is often mapped to an DELETE statement.
There are other methods, but we will keep things simple by ignoring them. Each method can itself perform several related actions, depending on the parameters in the URI, HTTP header in the request or an associated JSON payload.
To be true to REST, we should never include specific actions in the URI. For example, the following would be considered wrong.
Using this type of URI would be considered Remote Procedure Call (RPC) over HTTP, not REST.
HTTP response codes are used to determine success or failure. Typically a successful GET, PUT or DELETE call will return a 200 success response, while a successful POST call will return a 201 created response. It makes sense to output additional information about errors, rather than relying solely on the HTTP return codes.
REST does not dictate the output returned by a web service call. Some companies will attempt to standardise their approach, but this is not SOAP and no rigid format is forced. Useful starting points to see what you should be aiming for are listed below.
- JSON Schema: A Media Type for Describing JSON Documents
- JSON Hyper-Schema: A Vocabulary for Hypermedia Annotation of JSON
- Google JSON Style Guide
Oracle REST Data Services (ORDS) is a WAR file (ords.war) that can run in standalone mode, under Tomcat or WebLogic. These articles explain how to install, configure and run ORDS.
- Oracle REST Data Services (ORDS) : Installation on Tomcat
- Oracle REST Data Services (ORDS) : Standalone Mode
- Oracle REST Data Services (ORDS) : Configure Multiple Databases
ORDS was originally known as the "APEX Listener", which was a replacement for , an Apache module that was part of the Oracle HTTP Server. You will often see ORDS in APEX architecture diagrams such as this.
As more functionality was added, it got renamed to ORDS, which better reflects its functionality. In addition to fronting APEX and other PL/SQL Web Toolkit applications, ORDS enables RESTful web services for Oracle databases (10g upward) and the Oracle NoSQL Database. It also allows access to the 12c JSON Document Store using SODA.
How does ORDS enable RESTful web services?
