Creating RESTful Services in DataFlex: Difference between revisions
m Typo |
m Link |
||
Line 3: | Line 3: | ||
It is often said that REST is not CRUD, by which it is meant that REST operations should not simply be considered as the basic database operations: '''C'''reate, '''R'''ead, '''U'''pdate and '''D'''elete. | It is often said that REST is not CRUD, by which it is meant that REST operations should not simply be considered as the basic database operations: '''C'''reate, '''R'''ead, '''U'''pdate and '''D'''elete. | ||
And this is true, however REST <u>does</u> provide us with the tools to perform those operations. As discussed under [[#Verbs|Verbs]] above, the verb PUT is unsuitable for most database operations, due to the requirement that it be idempotent. This leaves us with the verbs GET, POST, PATCH and DELETE, which ''do'' map nicely onto those database operations: | And this is true, however REST <u>does</u> provide us with the tools to perform those operations. As discussed under [[RESTful Service Theory#Verbs|Verbs]] above, the verb PUT is unsuitable for most database operations, due to the requirement that it be idempotent. This leaves us with the verbs GET, POST, PATCH and DELETE, which ''do'' map nicely onto those database operations: | ||
*'''C'''reate - '''POST''' (to a ''collection'', since in general the instance ID will not be known, but will be a serial ID allocated by the application) | *'''C'''reate - '''POST''' (to a ''collection'', since in general the instance ID will not be known, but will be a serial ID allocated by the application) |
Revision as of 14:28, 7 August 2019
REST is not CRUD, but...
It is often said that REST is not CRUD, by which it is meant that REST operations should not simply be considered as the basic database operations: Create, Read, Update and Delete.
And this is true, however REST does provide us with the tools to perform those operations. As discussed under Verbs above, the verb PUT is unsuitable for most database operations, due to the requirement that it be idempotent. This leaves us with the verbs GET, POST, PATCH and DELETE, which do map nicely onto those database operations:
- Create - POST (to a collection, since in general the instance ID will not be known, but will be a serial ID allocated by the application)
- Read - GET (to either a collection, to return a list of its instances, or to an instance to return details of that)
- Update - PATCH (to an instance, to modify elements of it)
- Delete - DELETE (to an instance, to delete it)
We can see from the above that, for basic purposes, we can treat database tables as collections and rows within them as instances. For the simple examples on the two pages below, we will do that, which will provide us with a kind of "DataBase Explorer" type access to our data, although mediated by the Data Dictionaries and their rules. (You did put all your business rules into your data dictionaries, didn't you? Of course you did! <g>)
More complex REST operations will be dependant on the system in question, however the examples in the pages linked to below should point the way to how to expose (or not!) the contents of your database through a RESTful API.
For how you might create a simple RESTful service using DataFlex "out of the box", see A Simple RESTful Service.
To use the REST library to create a RESTful service, see Using the REST Library.