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

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023