Web Connection
REST Service
Gravatar is a globally recognized avatar based on your email address. REST Service
  Luca
  All
  Feb 24, 2017 @ 05:48am

Dear Rick, I am implementing REST service into my web application and I am following your tutorial.
I have 2 questions:

  1. if I do some query into the REST service and I have to return a cursor, where can I close it?
    I cannot close it before the RETURN.
    I tried to add Function Dispose() to the service and it closes cursors.
    Is it the right way to close temporary tables?

  2. I passed a parameter to ask records of first December 2016 from a data field and the method returned a data like
    "2016-11-30T23:00:00Z"

{

    "idfunziona": "A0X2",
    "dataprod": "2016-11-30T23:00:00Z",
    "idprod": "005",
    "idrecord": 337527

},
{

    "idfunziona": "A0X2",
    "dataprod": "2016-11-30T23:00:00Z",
    "idprod": "005",
    "idrecord": 337825

}

Please how to convert data string into first December 2016?

Thank you very much for support

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Rick Strahl
  Luca
  Feb 24, 2017 @ 02:06pm

If you return a cursor to the REST service for rendering as JSON with return cursor:ResultCursor, you can't explicitly close the cursor. That's because the service needs to access the cursor after the request is done in your code in order to serialize it.

My recommendation is use the same cursor name always (like TQuery for example) and don't worry about the cursor staying open for one request. It'll be closed and overwritten in the next request.

You can also override the OnProcessComplete() or in the Service OnAfterCallMethod(@lcResult) method in the service class and close anything there, but this method is called for every method of the process class, so you'd have to selectively check for each request to figure out which cursor to close.

Using a reusable cursor is by far the easiest thing though - doing this leaves a single (or maybe a few) cursors open at any time which is not an issue. What you worry about is having lots and lots of cursors open all the time.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Luca
  Luca
  Feb 25, 2017 @ 07:58am

Thank you Rick.
And what about the data value ("2016-11-30T23:00:00Z") returned from table instead of first December 2016?
How to extract (or convert) data values correctly?
Sincerely

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Harvey Mushman
  Luca
  Feb 26, 2017 @ 07:09am

With respect to the date, I suspect if you use Moment JS it will be fixed. I think it comes from the UTC offset.

realDataProd = moment(dataprod).format('YYYY-MM-DD')

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Luca
  Harvey Mushman
  Feb 26, 2017 @ 07:54am

Many thanks Harvey.
I see the Moment() however how I use it into a function like the following where I have to return formatted dates as YYYY-MM-DD?
Sincerely

********************
FUNCTION Test()
********************
	SELECT DataProd ;
	FROM MyTable ;
	INTO CURSOR Query

	RETURN "cursor:Query"
ENDFUNC 

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Rick Strahl
  Luca
  Feb 26, 2017 @ 02:29pm

If you're using the West Wind client libraries for your JSON parsing it'll automatically convert dates back to dates.

For other clients external to your app - that'll be up to the consumers to handle. +++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Luca
  Rick Strahl
  Feb 28, 2017 @ 12:07am

Dear Rick,
as I said I am implementing REST service into my web application and I am following your tutorial Step by Step: Creating a JSON REST Service.
I followed the New Process Wizard to create a new REST service and a new scriptmap .rs on the development machine.
Please what about the server: do I have to create manually the new scriptmap on the server?
Sincerely

Gravatar is a globally recognized avatar based on your email address. re: REST Service
  Luca
  Harvey Mushman
  Feb 28, 2017 @ 12:29am

Dear Harvey,
I solved in this way:

********************
FUNCTION Test()
********************
	SELECT ToIsoDateString(DataProd) as DataProd ;
	FROM MyTable ;
	INTO CURSOR Query

	RETURN "cursor:Query"
ENDFUNC
© 1996-2024