#1 2016-11-03 00:03:52

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

Implement RESTful with specification already designed

Is it possible to implement following RESTful API specification with mORMot? (please note this is not a database application, and the RESTful API is already published)


To create a user:

POST root/api/admin/user

with request Body:
{
"adminUserid" : "joe",
"adminPassword" : "password",
"orgUserid" : "GHRestOrg" ,
"orgPassword" : "password123" ,
"orgName" : "Test Rest Organisation" ,
"orgTelephone" : "04-345-1234",
"orgCorrespondenceEmail" : "info@test.com" ,
"orgAddress" : "Plato Towers, No 300/10" ,
}

I guess what I wanted to know is if there is a way to use custom URI and JSON format of request and response.
As far as I am aware, mORMot's interface based/method based services have different URI and JSON schema compare to above specification.

Offline

#2 2016-11-03 10:21:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Implement RESTful with specification already designed

You can send the parameters as a JSON object body, even with interface based services.
You may define e.g. IAdmin interface and the corresponding method:

  procedure User(const adminUserId, adminPassword, orgUserid, orgPassword, orgName, orgTelephone, orgCorrespondenceEmail, orgAddress: RawUTF8);

Then you can override the routing class to match your expectations at URI level.

With method-based services, you have access to all internals in the Ctxt, so you can accept whatever.

Offline

#3 2016-11-03 23:17:31

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

Re: Implement RESTful with specification already designed

ab wrote:

You can send the parameters as a JSON object body, even with interface based services.
You may define e.g. IAdmin interface and the corresponding method:

  procedure User(const adminUserId, adminPassword, orgUserid, orgPassword, orgName, orgTelephone, orgCorrespondenceEmail, orgAddress: RawUTF8);

Then you can override the routing class to match your expectations at URI level.
...

Thanks ab, I will try "JSON object body".

Last edited by Bo (2016-11-03 23:18:58)

Offline

#4 2016-11-04 12:31:57

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

Re: Implement RESTful with specification already designed

Hi ab,

I have read the framework document again regarding "send the parameters as a JSON object body" and response format, I believe that what you have suggested is doable. But I have not found how to return errors as http status code, because my specification requests it to return http 400 error when parameter validation failed. How do I achieve that?

Thanks,

Offline

Board footer

Powered by FluxBB