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

Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024
Ortus February Newsletter 2024

Ortus February Newsletter 2024

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
March 06, 2024
Unveiling the Future of CFML Development - 3rd Round of Sessions

Unveiling the Future of CFML Development - 3rd Round of Sessions

Welcome back to our journey into the future of CFML development! As excitement continues to build for Into the Box 2024, we're thrilled to bring you the latest updates on what promises to be a transformative event. Continuing our blog post series, let's delve deeper into the third wave of session releases and discover the key surprises awaiting attendees. Learn More

Maria Jose Herrera
Maria Jose Herrera
March 01, 2024