Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 25
Registered: ‎02-04-2013
My Device: Torch
My Carrier: T-Mobile

Rest API Import

Good morning all,

I am trying to use a REST API but I don't really know what to import in order that I can input the url.  Any help is greatly appreciated.

 

Thanks in advance!
Peter

Developer
Posts: 16,643
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Rest API Import

REST is usually JSON, which is supported since 6.0 (beforehand with an external lib).
you download the json string, for example by using HttpConnection and IOUtils, and handle it using the JSON libs.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 31
Registered: ‎08-05-2011
My Device: 9550
My Carrier: Vodafone

Re: Rest API Import

Are you delaing with HTTP GET or POST???


/*********************************************************************/
Please press the like button on the right side to thank me if my reply helped you and please mark posts as solved if you found a solution.
Developer
Posts: 31
Registered: ‎08-05-2011
My Device: 9550
My Carrier: Vodafone

Re: Rest API Import

Try this GIT opensource library for all the JSON parsers if you using on the older versoins of Blackberry.

https://github.com/upictec/org.json.me

/*********************************************************************/
Please press the like button on the right side to thank me if my reply helped you and please mark posts as solved if you found a solution.
Contributor
Posts: 25
Registered: ‎02-04-2013
My Device: Torch
My Carrier: T-Mobile

Re: Rest API Import

I need to make both from what I understand

Contributor
Posts: 25
Registered: ‎02-04-2013
My Device: Torch
My Carrier: T-Mobile

Re: Rest API Import

Hello mayureshq,


Thank you for your reply.  From what I understand I am supposed to make both the GET and POST.  Also I am trying to make this for BB versions 7.0 and above.  Does this change anything?

Developer
Posts: 16,643
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Rest API Import

if your questions are that basic this should help you out:
http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Implementing-JSON-in-your-applic...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 25
Registered: ‎02-04-2013
My Device: Torch
My Carrier: T-Mobile

Re: Rest API Import

Hey Simon,

Thank you for your response. I am trying to follow the code and the code seems pretty straight forward but I don't see where I can edit the url where I am pushing my information to and where I am receiving it.
New Developer
Posts: 134
Registered: ‎01-11-2011
My Device: curve

Re: Rest API Import

Hi pxlam15

Below is the code to send your Json object to server.

finalObject is a Json object.

 

 

hc = (HttpConnection) Connector
.open(URL);
hc.setRequestMethod(HttpConnection.POST);

hc.setRequestProperty("Content-Type", "application/json");
os = hc.openOutputStream();
String data = "placeOrder=" + finalobject.toString();
os.write(data.getBytes());
os.flush();
os.close();