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

BoxLang 1.0.0 Beta 23 Launched

BoxLang 1.0.0 Beta 23 Launched

The latest release of BoxLang, Beta 23, marks a significant step forward in our journey to create the ultimate dynamic language for the JVM. Packed with powerful new features, important bug fixes, and thoughtful optimizations, this update is designed to make your development experience smoother, faster, and more reliable, especially after now starting to take 100s of comments and bug reports from our community.

Luis Majano
Luis Majano
November 23, 2024
TestBox Latest Updates and News!

TestBox Latest Updates and News!

We’re thrilled to have launched the new TestBox website and TestBox 6.0! If you haven’t had a chance to explore yet, visit TestBox to discover updated documentation, powerful resources, and features that make testing more efficient than ever.

Maria Jose Herrera
Maria Jose Herrera
November 21, 2024
Is Your ColdFusion Application Ready for the Future?

Is Your ColdFusion Application Ready for the Future?

In a rapidly evolving digital world, maintaining performance, security, and scalability for ColdFusion applications is more challenging than ever. Whether you're using Lucee or Adobe ColdFusion, legacy systems can become a bottleneck for growth, innovation, and user satisfaction. The need to future-proof your ColdFusion applications has never been more critical.

But where do you start?


The Hidden Costs of an Outdated ColdFusion Application

As you...

Cristobal Escobar
Cristobal Escobar
November 21, 2024