[fpc-pascal] fpWeb REST support (asking about features)
idokan at gmail.com
Tue Jun 7 19:24:15 CEST 2011
On Tue, Jun 7, 2011 at 17:49, <michael.vancanneyt at wisa.be> wrote:
> On Tue, 7 Jun 2011, Ludo Brands wrote:
> Ok, that is simply an alternative to the current
>>> TFPWebDataModule which does
>>> not rely on part of the URL to determine the CRUD action, but
>>> uses the URL
>>> just to determine the resource, and the HTTP method to see
>>> which CRUD action
>>> needs to be performed.
>>> That's easily done. It's about 5 lines of code in
>>> TFPWebDataModule: 1 for a "RESTFul" property, 4 to determine
>>> the action from the method if RESTFul is set to True.
>>> Do you think this would be a useful addition ?
>> That would indeed be a very good starting point for a REST implementation.
>> In the few REST implementations I have seen, the uri is used to pass on
>> record identifier for the RUD action while, if I understand correctly,
>> TFPWebDataModule gets the record identifier together with the data from a
>> datainputadaptor. This will probaly need a customised datainputadaptor
>> a record identifier can be anything.
> Indeed. In fact, the implementation should go in the web input adaptor.
To be "RESTful" (I'm talking about HTTP), you do not pass the parameters of
"GET,DELTE" etc.. as a parameter, but as part of the HTTP Protocol, that is:
GET /names HTTP/1.1
DELETE /names HTTP/1.1
As you know REST is an architecture, not just a set of classes or methods.
> REST doesn't even require HTTP. So calling a webserver class RESTsomething
> because onGet, onPut, etc. are exposed does not have any added value.
>I agree. This was why I didn't understand the original poster's question;
>implementation is trivial.
At the moment we are talking about HTTP, so TFPREST... for HTTP CGI is
actually in order.
The issue is not about writing 10 lines of code each time you need
to separate GET from PUT, but the fact that you repeat yourself 10 lines of
code on each location you require to this separation.
I'm using such work for example in Sinatra <http://www.sinatrarb.com/>. I
have an API for having recordings after few of my applications (Asterisk
based) finished working. so you do the following:
GET /recording/filename HTTP/1.1
DELETE /recording/filename HTTP/1.1
So you can download the recording (if exists) and delete it when no longer
If I require to implement the same thing on fpWeb, it actually takes more
code because there is no separation of any kind.
At the moment I wish to create a CRUD engine in fpWeb (and keep it open
source) that had a layer above databases, so you do not provide direct
access to the database, but you provide access to the data, like a Proxy,
but in HTTP, so instead of using SQL (for example) you use JSON, and instead
of using Pg, Fb, MySQL, SQLite etc... it is agnostic, and you control what
user can do what type of access and action etc...
Sure you can do so at the moment ,but you will repeat your code or write way
too general code for something like that. Having OnGet etc... provide easier
way not to repeat yourself and even making the code much more readable
and maintainable imho.
I Hope that is more clearer now.
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal