Recent

Author Topic: [mORMot2.0] Questions from a noob trying to do a RESTful API  (Read 622 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1329
  • Professional amateur ;-P
[mORMot2.0] Questions from a noob trying to do a RESTful API
« on: October 14, 2025, 02:29:53 am »
Hey Y'All,

While embarking on the task of upgrading the backend side of OPM, I've decided I'm going to FINALLY start using mORMot 2.0!!

I've started my experimentation and I got to the point where I'm serving some content from a temporary SQLite database. The idea is to use PostgreSQL in production.

I'm a bit surprised by some of the conventions that mORMot 2.0 imposes. I was counting on it being opinionated, like any other framework, but nonetheless, some of the opinions are rather strange from someone that is used to CakePHP that takes the same opinionated ideas from Ruby on Rails.

All this long winded blah-blah to get to my immediate questions:
  • How do I replace the /root endpoint with /api/v1, without using routes?
    Cuz at the moment I am using routes, but the /root endpoint is still there. Sooo, no aliasing is kinda what I want.
  • How do I force the table names for each model?
    I much prefer that both the tables and the fields be in lower case. I also like my models to be in the singular, but my tables to be in the plural.
    Yeah, I know, I'm a bloody whiner, but I'm old and I have my own conventions :P
  • How do I change the case for the JSON that is served?
    I'm rather spoiled by the fact that in Go I can define the JSON name for each field, and I'm wondering if I can do the same with mORMot 2.0

I think this is enough for now. When I have some other doubts, I'll keep adding to this thread.

Cheers,
Gus
« Last Edit: October 14, 2025, 03:15:13 am by Gustavo 'Gus' Carreno »
Lazarus 4.99(main) FPC 3.3.1(main) Ubuntu 25.04 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1329
  • Professional amateur ;-P
Re: [mORMot2.0] Questions from a noob trying to do a RESTful API
« Reply #1 on: October 14, 2025, 02:51:34 am »
Hey Y'all,

I stumbled upon the answer on how to replace /root with /api/v1!!


As simple as this:

Code: Pascal  [Select][+][-]
  1. procedure TRESTServer.Crea]"]>Blockeddels;
  2. begin
  3.   FModel:= TOrmModel.Create([
  4.     TORMPackages
  5.   ], 'api/v1');
  6. end;

EDIT: Somehow, the code above has a glitch and the string ]"]>Blocked shows ?!?!

OKIDOKES, that's one down and two to go ;)

Cheers,
Gus
« Last Edit: October 14, 2025, 03:20:14 am by Gustavo 'Gus' Carreno »
Lazarus 4.99(main) FPC 3.3.1(main) Ubuntu 25.04 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1329
  • Professional amateur ;-P
Re: [mORMot2.0] Questions from a noob trying to do a RESTful API
« Reply #2 on: October 14, 2025, 11:41:42 am »
Hey Y'all,

Since I solved one, lets get the count back up...

Does this:
Code: [Select]
opmapi:  WARNING: deprecated SQLite3 engine
opmapi: Static SQLite3 library as included within /home/gcarreno/Programming/OPM2.0/bin/opmapi is outdated!
Linked version is 3.46.1 whereas the current/expected is 3.44.2.

Please download latest SQLite3 3.44.2 revision from
https://synopse.info/files/mormot2static.tgz

Mean that my version of SQLite lib*.so is newer or older?
I just installed mORMot 2.0 today, and did the above download also...
I'm a bit confused by this warning...  :o

Cheers,
Gus
Lazarus 4.99(main) FPC 3.3.1(main) Ubuntu 25.04 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1329
  • Professional amateur ;-P
Re: [mORMot2.0] Questions from a noob trying to do a RESTful API
« Reply #3 on: October 15, 2025, 12:51:42 pm »
Hey Y'All,

Pounding one more question: Is there a way to do database migrations outside the main application?

I ask this because I got, kinda, spoiled from using CakePHP's migrations. With these you can do up/down quite easily, and all those migrations are just another source file you add to the source control. On top of that, they are timestamped and some info is stored in the database itself, to track which ones have been applied.

It would be rather nice to have something of this nature to use.

Cheers,
Gus
Lazarus 4.99(main) FPC 3.3.1(main) Ubuntu 25.04 64b Dark Theme
http://github.com/gcarreno

abouchez

  • Full Member
  • ***
  • Posts: 134
    • Synopse
Re: [mORMot2.0] Questions from a noob trying to do a RESTful API
« Reply #4 on: October 15, 2025, 09:44:56 pm »
Discussion continued on our forum:
https://synopse.info/forum/viewtopic.php?id=7406
 ;D

It is indeed a nice place to ask such questions.

 

TinyPortal © 2005-2018