You are not logged in.
Pages: 1
I'd like to play more with mORMot.
Now, I would like to create a schedule project meetings with (mORMot + jQuery). This project is based on a fictional company called NorthWind Traders has 10,000 employees.
For example, when I type into the address bar: http://localhost:8080/root/Employee/10
it returns this:
{
"ID" : 10,
"EmployeeID" : 4,
"FirstName" : "John",
"LastName" : "Williams",
"ManagerID" : 1,
"Title" : "VP of Engineering",
"Department" : "Engineering",
"OfficePhone" : "617-000-0004",
"CellPhone" : "781-000-0004",
"Email" : "jwilliams@fakemail.com",
"City" : "Boston, MA",
"Picture" : "john_williams.jpg"
}
____
I need to create a dedicated method server, or interface-based server to return custom JSON and pass dynamic parameter in a query. Something like: "http://localhost:8080/root/Employee/?id=12"
[{
"EmployeeID" : 12,
"FirstName" : "Kathleen",
"LastName" : "Byrne",
"ManagerID" : 5,
"Title" : "Sales Representative",
"Department" : "Sales",
"City" : "Boston, MA",
"OfficePhone" : "617-000-0010",
"CellPhone" : "781-000-0010",
"Email" : "kbyrne@fakemail.com",
"Picture" : "kathleen_byrne.jpg",
"managerFirstName" : "Ray",
"managerLastName" : "Moore",
"reportCount" : 0
}
]
This REST method should return custom JSON based on a query.
Query.Execute('SELECT e.employeeid, e.firstName, e.lastName, e.managerId,'+
'e.title, e.department, e.city, e.officePhone, e.cellPhone, e.email, e.picture,'+
'm.firstName managerFirstName, m.lastName managerLastName, count(r.id) reportCount'+
' FROM employee e left join employee r on r.managerId = e.employeeid'+
' left join employee m on e.managerId = m.employeeid WHERE e.employeeid=10 group by e.employeeid',true,[]);
I would like to pass dynamic parameter in e.employeeID=:id:
One can say you need a fair amount of knowledge to do anything serious with mORMot. This seems to be very basic, but I couldn't get through this. Ouch. mORMot for dummies you gotta be smart to use it.:)
I appreciate any idea, example.
Offline
Search and read for the "'method based service" paragraph in the SAD 1.18 pdf.
It will help you define your service.
See also sample "06 - Remote JSON REST Service".
Then use one of the ORM methods returning a JSON result, or directly a DB query.
Online
Thank you. I created a custom service, maybe not the best practice, it's working fine except for "extra Backslashes". When I type into browser bar: http://localhost:777/root/Employee?id=10
Response body is:
{
"result" : "[{\"EmployeeID\":10,\"FirstName\":\"Kathleen\",\"LastName\":\"Byrne\",\"ManagerID\":5,\"Title\":\"Sales Representative\",\"Department\":\"Sales\",\"City\":\"Boston, MA\",\"OfficePhone\":\"617-000-0010\",\"CellPhone\":\"781-000-0010\",\"Email\":\"kbyrne@fakemail.com\",\"Picture\":\"kathleen_byrne.jpg\",\"managerFirstName\":\"Ray\",\"managerLastName\":\"Moore\",\"reportCount\":0}]\n"
}
Does anyone can shed any light as to why my JSON is coming out with the extra backslashes?
mORMot server is returning text containing backslashes and quote characters. That a json string inside an json output, I you need to parse it twice.
Last edited by warleyalex (2013-06-12 23:38:32)
Offline
{ "result" : "thank you" }
Offline
Pages: 1