Creating RESTful Services in DataFlex: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
Creating (splitting up original article)
 
Different article
 
(5 intermediate revisions by the same user not shown)
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]] (in the RESTful Service Theory article), 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)
Line 10: Line 10:
*'''D'''elete - '''DELETE''' (to an ''instance'', to delete it)
*'''D'''elete - '''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>)  
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 in the two articles 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.
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]].
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]].
To use the REST library to create a RESTful service, see [[Using the REST Library]].
Line 20: Line 20:
==See also==
==See also==


*[[REST]]
*[[RESTful Service Theory]]
*[[RESTful Services in DataFlex]]
*[[RESTful Services in DataFlex]]
*[[Consuming RESTful Services in DataFlex]]
*[[Consuming RESTful Services in DataFlex]]


[[Category:REST]]
[[Category:REST]][[Category:Web Services]]

Latest revision as of 17:34, 23 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 (in the RESTful Service Theory article), 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 in the two articles 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.

See also