Jump to content
omnibrain

THttpAppSrv - Add*Handler for PUT and DELETE

Recommended Posts

I'm currently designing a REST API for a larger existing Delphi application and I'm currently looking into various options. I don't need a lot of "magic", I actually prefer my code to be straight forward so THttpAppSrv looks great to me. I should be able to implement most of my endpoints in GET and POST-Handlers. But for some PUT and DELETE would make more sense.

 

How would I best implement PUT and DELETE? Should I work around and just use GET and POST for everything? Can I somehow use a "generic" dispatch with THttpAppSrv, handle PUT and DELETE there and use the GET- and POST-mechanism as provided? Or would it be easy to add PUT- and DELETE-Handler "infrastructure" to THttpAppSrv? I tried looking into the code, but I'm not familiar with ICS so it's all greek to me...

Share this post


Link to post

I'll look at adding the missing handlers in the next week or so.

 

You may want to look at a new SSL sample, OverbyteIcsDDWebService.dpr which is very similar to OverbyteIcsSslMultiWebServ.dpr, but designed as a Windows service, although
it will also run as a GUI for debugging.  It requires DDService service framework to be installed from https://www.magsys.co.uk/delphi/ddservice. asp.

 

It also includes a REST server with simple lookup responses from a SQL database, which optionally requires DISQLite3 to be installed from http://www.yunqa.de.  Note this sample in not in the project groups due to these pre-requisites.

 

This sample is part of the next release, in SVN and the overnight zip.  It is effectively a working REST server, very similar to a commercial server I've written at https://api.telecom-tariffs.co.uk/

but you need a login to do actual REST requests. 

 

Angus

  • Like 1

Share this post


Link to post

Thanks a lot.

 

I'm going to take a look at the new example code. The examples are always helpful.

Share this post


Link to post

Beware the ICS web server samples include a lot of code for dynamic demonstration pages, which you can mostly remove to give yourself the basis of a commercial web server service listening on multiple IP addresses. ordering SSL certificates and with request logging. However the REST sample page is implemented as a virtual page not a URL handler, other pages are URL handlers.

 

The main issue with the current ICS web server being a single thread, so blocking SQL calls can reduce performance.  My experience over 10 years is my SQL calls mostly take 10ms or less, so the performance hit is minimal, it can still support 50 requests a second (but not new SSL connections). 

 

The long term ICS wish list has a heavy web server, that will be configurable to allow x connections per thread, down to one if they are effectively blocking.

 

Angus

  • Like 1

Share this post


Link to post

SVN has been updated with a new OverbyteIcsHttpAppServer adding support for PUT and DELETE verbs, also OverbyteIcsDDWebServiceSrv.pas now uses TUrlHandlerRestApi instead of as a virtual page, little simpler.

 

Angus

 

  • Like 1

Share this post


Link to post

After I updated ICS (to 8.68) I added the handlers for PUT and DELETE, but it looks like I never tested them properly. My process produces only "501 Unimplemented".

 

I wanted to try your example OverbyteIcsDDWebService.dproj because there you added the handlers, but I couldn't compile it. I had to add 'OverbyteICSURl' to the Uses of 'OverbyteIcsDDWebServiceSrv' and Answer String in line 2398 misses the code page argument.

After fixing that I could compile and start (after editing the .ini) the process. But there it also throws an "501 Unimplemented" for the put handler when calling delete for "restapi.html. In the end I needed to add the options 'hoAllowPut' and 'hoAllowDelete'.

After I added them on my project the calls work as well. 

 

So I can say it works now, but your example may need some minor tweaks.

Share this post


Link to post

I don't test OverbyteIcsDDWebService for each new release because it has dependencies outside ICS, but it is next on my list to add support for OCSP, next week as well. 

 

Angus

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×