Create your own API

What's the idea ?

Troglio turns Trello into a CMS. What it actually does is: format raw data from cards into a website representation, then it posts this representation wherever you want.

But... what's the difference with just pulling data from Trello's API ?

Well, you could in fact connect to Trello's API, pull data at your convenience, then use it like you want. But this is somewhat inconvenient: - you should wait for Trello's API each time you need data. Even if they have unbelievable stable response times, it can get complicated when you need to serve static pages to google bots for example... - once you have the data, it is not formatted rather it is just raw. You could maybe get satisfactory data out of the description alone but it falls apart very quickly.

With troglio, you get: - metadata: using easy key/value syntax you can add as many structured properties/fields as you need without any setup. - defaults: all pages have an URL, a type. a template etc... You or your users won't break things by omitting the URL of page... troglio will infer one for you automagically. - master/detail relationship: one card can control properties of others, so you don't have to repeat things like "type = post" on each cards. You just setup it once for a given list and forget it.

Now here is what we think makes troglio a neat alternative to our beloved competitors: we don't hold your data in hostage. You decide how you want to manage your data: we ship them to you directly. Now you have the power to decide whether or not you want to : - Use data locally on your project or - Let those data to be served as an API endpoint of your choice

And this is what this post is about: show you how to put build an API if that's what you prefer or if your project dictates it this way.

Get Troglio

Ok, let's head over trello.com now and create a new board. Call your board whatever you want, the only setup we want to make is to activate the troglio power-up. You just find it in the "developers" section of so-called power-ups. (to find power-ups in Trello, just open the right menu, then locate "Power-Ups")

Once troglio power-up is activated, enters light setup part. In the upper right corner of the board, you should see something like "Get started with troglio". Well... click on it !!! Following the steps should be pretty straightforward: just select the git repository you want us to push data to. (please do select a git provider and not a custom URL)

Once you saved the repo you wanted, how can I say it.... it's done ! You should see a "Publish" button in lieu of the previous one. By clicking this very button, you just tell troglio to perform its black magic and push pages into your repo with all neat things like : route, title, slug, template... and more.

Just click "Publish" and go check your git repository. If all went well, you should see a new folder called "troglio" with a JSON file called "pages.json". This JSON document will be REPLACED with new data whenever someone presses "Publish !". Simple as that.

Now "where is my magic API stuff ?"

The whole trick is that now, WE HOLD OUR DATA. So we can do whatever we want. For instance, what we want to do now, is serve this JSON data into multiple JSON files. To be more precise, we want to get the "troglio/pages.json" file, and split its content by as many published cards we have in our Trello board. It takes 5 lines of code to make this now:

// splitTroglioPages.js

We could setup everything with github only, but we can benefit from faster response times if we use a CDN. What is a CDN you say ? Let's not get into details, just understand that a CDN is like a classic host server, but it will duplicate your pages in multiple servers around the globe, so that your content can live closer to your potential audience, resulting in insanely fast response times.

We recommend Netlify as a CDN host: they are reliable, fast and easy, plus they are really cool folks. Just open account here.

In Netlify, you can connect to your git provider a la troglio and just enters the build command: npm run build and the deploy path public.

Save that, and you should see everything being built. Once finished, Netlify will deploy your pages to their CDN as application/json content. So just browse your brand new API and eventually it should now be automatic: endpoints and content will live with your Trello cards.

Enjoy your static API without headache, updated by your users, from easy trello cards.... Isn't that cool ?! :)