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 7 Launched

BoxLang 1.0.0 Beta 7 Launched

We are pleased to announce the release of BoxLang 1.0.0-Beta 7! This latest beta version includes improvements and essential bug fixes, but more importantly it certifies the execution of ColdBox HMVC and TestBox.

What is BoxLang?

BoxLang is a modern dynamic JVM language that can be deployed on multiple runtimes: operating system (Windows/Mac/*nix/Embedded), web server, lambda, iOS, android, web assembly, and more. BoxLang combines many features from different progr

Luis Majano
Luis Majano
July 26, 2024
New BoxLang Feature: Java Method References and Higher-Order Functions

New BoxLang Feature: Java Method References and Higher-Order Functions

We’ve added more goodies to our BoxLang Java interop: method references and higher-order functions. CFML has never let you do these things, making Java Interop feel like a second-class citizen. But with BoxLang, we’re elevating Java integration to a new level.

Maria Jose Herrera
Maria Jose Herrera
July 26, 2024
Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Are you a CFML developer looking to take your skills to the next level? Look no further than the ColdBox from Zero to Hero Virtual Live Training! This intensive two-day course will equip you with the knowledge and expertise to build robust and scalable applications using ColdBox 7, the latest version of the most popular CFML MVC framework.

What You'll Learn:

  • Master the Fun...

Cristobal Escobar
Cristobal Escobar
July 24, 2024