Help with Exposing REST Services

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
RentProperty
Posts: 345
Joined: Mon Nov 12, 2012 9:08 pm
Location: South Africa

Help with Exposing REST Services

Post by RentProperty »

Hi Guys

We are trying to expose a service. We want to return an object based on parameters supplied by the request. However it seems the request is creating an instance of the object we are trying to return and then it returns that instance instead of the one we are looking for.

Our service is setup for REST support and to return a single instance of an Object USING JSON.

Our process says:

Find MyObject Where MyObject.Loginname=ThisMyObject.LoginName

We set MyObject as input.

Any Help will be much appreciated! Please let me know if you require more information.

Kind Regards

Werner
Hein Hanekom & Werner Hanekom
Sinov8.net
AwareIM Version 5.9 | 6.0 | 7.0 | 7.1 (Windows EC2 R2012 & MySQL)
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Post by chris29 »

Hi Werner

I have a lot of the restful services setup.

One thing to about setting them up is that the object you use as input should be different to the object your trying to find.

The service creates a row and set the value to the matching attributes.

How you create this service depends on how you want the output.

EG:

Create an Object 'MyObjectInput' with the attribute LoginName

In you process ;

FIND MyObject WHERE MyObject.Loginname=ThisMyObjectInput.LoginName

and return MyObject to the service.


For a Service that doesn't require parameters then you don't need an object (Input) to the process.


I hope this helps.

Chris
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
RentProperty
Posts: 345
Joined: Mon Nov 12, 2012 9:08 pm
Location: South Africa

Post by RentProperty »

Thank You Very Much Chris :-) Much appreciated

That's what I thought we might have to do so we created a 'ServiceObject' that will contain all the attributes for any possible service and then we'll just use the attributes applicable to a specific service we are calling.

Works perfectly. Just thought there might be a more efficient way. So I Assume you also have a scheduled process that delete all these objects then Once a day/month.

Kindest Regards

Werner
Hein Hanekom & Werner Hanekom
Sinov8.net
AwareIM Version 5.9 | 6.0 | 7.0 | 7.1 (Windows EC2 R2012 & MySQL)
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Post by BenHayat »

Thank you Werner & Chris for this post. Since the docs are kind of limited on the REST, any Input is appreciated.
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Help with Exposing REST Services

Post by RLJB »

Hey guys I need some help on exposing a REST service pls.

I have it exposed and working with no parameters, but now I'm trying to add params. It isn't working (returns blanks), my REST URL is:

http://MYIP/AwareIM/REST/test/GetAlerts?StaffNumber=22

Questions:

The process input on the Service - does it need to have a CREATE statement to store the incoming parameter? If it does, how do i refer to them eg CREATE AlertInput WITH AlertInput.StaffNumber=what?

If it doesn't need a create how do I use the paramter in my FIND query that returns the data, eg:

FIND Alert WHERE Alert.StaffNumber=ThisAlertInput.StaffNumber
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Re: Help with Exposing REST Services

Post by chris29 »

Hi Rod

All you need is an object (AlertInput) the represents the attributes you want as parameters.

This object (AlertInput) then needs to be the input for the process. A row will be created automatically by the service.

In the process

FIND Alert WHERE ALert.StaffNumber=ThisAlertInput.StaffNumber
whatever else.......


Chris
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Help with Exposing REST Services

Post by RLJB »

Hey Chris

Excellent - thanks mate - that cracked it, working a treat!

Cheers
Rod
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Help with Exposing REST Services

Post by RLJB »

Next question... is there a way to restrict the attributes being returned by the exposed web service?

For example, here is the web service response below, is there a way in Aware, to just return the Name and Body attributes?

Currently I'm using an implementing process that is just:

FIND Alert WHERE Alert.StaffKey=ThisGetAlerts.StaffKey

And it is returning:

Code: Select all

{
"response": [
{
"Name": "New Products", 
"Viewed": "No", 
"StaffKey": "aaa111", 
"Type": "News", 
"Number": 1, 
"Body": "There are lots of new products coming soon"}
,
{
"Name": "Customer Complaint", 
"Viewed": "No", 
"StaffKey": "aaa111", 
"Type": "Complaint", 
"Number": 2, 
"Body": "You have a new complaint case xyz"}
,
{
"Name": "Training Change", 
"Viewed": "No", 
"StaffKey": "aaa111", 
"Type": "Training", 
"Number": 3, 
"Body": "There has been a change in training event location tonight. The new address is: \n123 Main Street \nSydney NSW 2000 \nPlease be there at 1pm sharp."}
]
}
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Re: Help with Exposing REST Services

Post by chris29 »

Yes, Just create a reply object
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Re: Help with Exposing REST Services

Post by chris29 »

Also, don't use IN BATCHES OF as it's not supported in the rest implementation.
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Help with Exposing REST Services

Post by RLJB »

I'm still a bit lost Chris... I've got a reply object, it has 9 attributes, I only want to display 3 in the exposed webservice, can I do that?
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Re: Help with Exposing REST Services

Post by chris29 »

I mean another object that's just used as a reply object.

It can be identical just populate the attributes you want in the reply. If it's undefined it's not included in the response.
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Help with Exposing REST Services

Post by RLJB »

Ok, gotcha - tks Chris.

(I was trying to be lazy and use the one BO for all my Replies)
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Re: Help with Exposing REST Services

Post by chris29 »

The majority of replies I have created are to existing json layouts. So in all cases I build objects to represent this. These can become quite complicated but work very well.

The only issue with this is, you have to handle the cleaning of the data in the object after the reply. Currently (unless something has changed recently) you can't use Non Persistence objects.
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
hpl123
Posts: 2594
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Help with Exposing REST Services

Post by hpl123 »

chris29 wrote:The majority of replies I have created are to existing json layouts. So in all cases I build objects to represent this. These can become quite complicated but work very well.

The only issue with this is, you have to handle the cleaning of the data in the object after the reply. Currently (unless something has changed recently) you can't use Non Persistence objects.
Chris,
It sounds like you know your REST stuff. Any chance you could create a sample BSV for the "Tips & Tricks" section of the forum showcasing how to setup some REST service (both directions if possible i.e USE a REST service and EXPOSE a REST service. (I never used REST so if the both directions part sounds incorrect, you know why :). Hopefully you know what I mean). Thanks
Henrik (V8 Developer Ed. - Windows)
Post Reply