[fpc-pascal] Developing a mini ERP / web based development

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Sun Jul 7 11:29:17 CEST 2019


Hi,

Does FPC support annotations yet?

So in the future (or hopefully now), we could create something like what
many Java frameworks allow. Simply annotate a plain class to do the
magic for you - a massive reduction in boilerplate code. So we could end
up with a RESTful resource/controller as follows:


@Path('/troopers')
@Produces('application/json')
TStormtrooperResource = class(TObject)
  public
    @Path('/{id}')
    @GET
    function GetStormtrooper(@PathParam('id') id: string): TStormtrooper;

    @POST
    function CreateTrooper(trooper: TStormTrooper): TStormtrooper;
end;

function TStormTrooperResource.GetStromtrooper(const id: string):
TStormtrooper;
begin
  result := SomeDataAccessLayer.GetStormtrooper(id);
end;

function TStormTrooperResource.CreateTrooper(trooper: TStormTrooper):
TStormtrooper;
begin
  result := SomeDataAccessLayer.AddTrooper(trooper);
end;


So with a web browser or rest client, if you visit the endpoint
'/troopers/7' it will return a TStormtrooper object serialized as JSON
output. And also a POST to the endpoint '/troopers' will add a
Stormtrooper to your database.

If you wanted XML instead of JSON, simply changes the @Produces annotation.




On 04/07/2019 3:27 am, silvioprog wrote:
> class. The few lines below illustrates it:
> 
> ...
>   THello = class(TBrookAction)
>   public
>     procedure Get; override;
>   end;
> 
> procedure THello.Get;
> begin
>   Write('Hello Darius. I'm Brook on the Chromebook! :-)');
> end;
> 
> initialization
>   THello.Register('/hello');
> ...
> 
> If you run a Brook application containing these lines above, just navigate
> to "/hello" to get the message "Hello Darius. I'm Brook on the Chromebook!
> :-)" on your web browser and have a lot of fun.


Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp


More information about the fpc-pascal mailing list