Page 1 of 1

REST API ?

Posted: Tue Jul 31, 2012 12:38 pm
by gr211
Hi Broadleaf users !

Tried out the new 2.x branch today with a bit of success running with Tomcat/MySQL. One thing I have not figured out yet is the REST API and how to use it ?

I first thought it's be this Ajax blcAjax param but nope, it's a completely different thing. Would someone know where to find any documentation on the subject (either official or unofficial) ?

Many thanks,

Romain

Re: REST API ?

Posted: Tue Jul 31, 2012 1:46 pm
by aazzolini
http://docs.broadleafcommerce.org/current/REST.html

That should have everything you need!

Let me know if you run into issues.

Re: REST API ?

Posted: Tue Jul 31, 2012 2:28 pm
by gr211
I must be blind ;-) Thanks a lot.

Romain

Re: REST API ?

Posted: Fri Aug 03, 2012 8:00 am
by math7189
Hi,

I'm currently working on REST api, but newbie.

I need to communicate with another plateform with RPC, I'll use the webservice methods, but they return wrapper objects. I'm wondering if there is a way to directly get the object. For instance, I get a ProductWrapper and want to get the Product object.

Thanks

Re: REST API ?

Posted: Tue Aug 07, 2012 5:02 am
by math7189
Hi,

Any idea about my problem? This is very important for me. I don't really understand the mecanism of wrapper and how you could
retrieve the base object. Maybe the RPC could directly use the wrapper object returned but I don't know :/

Thanks

Re: REST API ?

Posted: Tue Aug 07, 2012 9:09 am
by aazzolini
Broadleaf doesn't provide the full objects for a few reasons.

Security - If you were asking for a customer for example, we wouldn't want to return the full Customer object as it would contain sensitive information such as the hashed password.
Speed - Passing in a subset of all of the attributes of an object speeds up serialization of the object and obviously results in a smaller payload.

However, we designed the REST API in a very extensible way. Let me give you an idea of how you could extend the attributes that are returned from the product endpoint.

--------------
Create a new class that extends ProductWrapper.

Add new attribute(s) that are annotated with @XmlElement (Just like ProductWrapper)

Override the wrap method to call the super.wrap method and then set your additional attributes

Override the bean called org.broadleafcommerce.core.web.api.wrapper.ProductWrapper with your extended ProductWrapper class in the same way you would normally override a Broadleaf bean.
--------------

Now, when you hit a catalog endpoint (such as /product/{id}), your additional attributes will show up. I'm fairly certain these steps will work, but I didn't write the REST API. Let me know if you run into any issues or have any other questions and I'll get the authors to chime in.