You are not logged in.
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
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
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
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