Blog

Gavin Pickin

December 15, 2016

Spread the word


Share your thoughts

At Ortus Solutions, we love the holidays, and we wanted to gift you a gift of developer productivity, we will share a few tips and tricks that will keep giving all year around. Brad Wood is doing 12 Tips of (CommandBox) Christmas, and I am going to share 12 Tips of (ContentBox) Christmas.

The 12 Tips of (ContentBox) Christmas - Day 1 - ContentBox APIIn today's day and age, it's API here, API there, here an API, everywhere an API. Rightfully so, because of mobile, javascript, working with APIs are not only convenient, but almost necessary. While building ContentBox, we have always been mindful of how we can expose ContentBox as an API. Since ContentBox is built on top of ColdBox, exposing data from ContentBox is probably much easier than you think. In this post, we'll show you how you can start using it, in seconds.

ContentBox API

In this example, I'm using a ContentBox site spun up using CommandBox. We have a homepage, which looks like this.

http://127.0.0.1:8589/

How do we get the page information from the ContentBox API?

The fastest way, instead of hitting this URL http://127.0.0.1:8589/
You hit this url http://127.0.0.1:8589/.xml

And this is what you get:

<?xml version="1.0" encoding="utf-8"?><page><content>&lt;p&gt;Support services&lt;/p&gt;

&lt;p&gt;&lt;p&gt;Sorry, no related content was found.&lt;/p&gt;&lt;/p&gt;

&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut odio. Nam sed est. Nam a risus et est iaculis adipiscing. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer ut justo. In tincidunt viverra nisl. Donec dictum malesuada magna. Curabitur id nibh auctor tellus adipiscing pharetra. Fusce vel justo non orci semper feugiat. Cras eu leo at purus ultrices tristique.&lt;/p&gt;
...

Click here for the full XML output

Look at all that lovely XML.
Ok, some of you might have just spat out your eggnog, but some people love xml. What would you prefer, json? We have you covered.

When you hit this URL http://127.0.0.1:8589/.json you get

{"content":"<p>Support services</p>\r\n\r\n<p><p>Sorry, no related content was found.</p></p>\r\n\r\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut odio. Nam sed est. Nam a risus et est iaculis adipiscing. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer ut justo. In tincidunt viverra nisl. Donec dictum malesuada magna. Curabitur id nibh auctor tellus adipiscing pharetra. Fusce vel justo non orci semper feugiat. Cras eu leo at purus ultrices tristique.</p>\r\n\r\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>\r\n\r\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut odio. Nam sed est. Nam a risus et est iaculis adipiscing. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer ut justo. In tincidunt viverra nisl. Donec dictum malesuada magna. Curabitur id nibh auctor tellus adipiscing pharetra. Fusce vel justo non orci semper feugiat. Cras eu leo at purus ultrices tristique.</p>\r\n\r\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>\r\n\r\n<p>&nbsp;</p>\r\n","children":[],"excerpt":"","isDeleted":false,"relatedcontent":[],"HTMLDescription":"","slug":"support","createdDate":"20 Jul 2013 03:38 PM","contentID":147,"publishedDate":"20 Jul 2013 03:38 PM","showInMenu":true,"categories":[{"slug":"coldbox","category":"coldbox"}],"contentType":"Page","HTMLTitle":"","expireDate":"N/A","modifiedDate":"Aug 5, 2016 2:42:30 PM PDT","customfields":[],"comments":[],"title":"support","featuredImageURL":"","allowComments":false,"HTMLKeywords":""}

 

That is pretty cool I think… but pages are bulky, what about blog posts, or lists of blog posts?

http://127.0.0.1:8589/blog.json gets you the blog listing page, in json, with 9 json objects in an array - click here to see output

http://127.0.0.1:8589/blog/disk-queues-77CAF.json is a blog post, in json, with several comments - click here to see output

Of course ContentBox does more than Blogs and Pages, check back to find out more about ContentBox as we continue our 12 tips of (ContentBox) Christmas.

Add Your Comment

Recent Entries

Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang 1.0.0 Beta 3 Launched

BoxLang 1.0.0 Beta 3 Launched

We are thrilled to announce the release of BoxLang 1.0.0-Beta 3! This latest beta version is packed with exciting new features and essential bug fixes, including robust encryption functionality, enhanced Java interoperability, and more efficient event handling. Key highlights include the introduction of query caching capabilities, seamless coercion of Java Single Abstract Method (SAM) interfaces from BoxLang functions, and support for virtual thread executors. So, let’s dive into the details of what’s new in BoxLang 1.0.0-Beta 3 and how you can start leveraging these updates today!

Luis Majano
Luis Majano
June 28, 2024