User blog:Taldin/API Version 3, First Impressions

(Techie Tuesday post.  Today I'm going to talk about getting back into the coder thing.  Nothing too fancy just yet, since I'm several months out of date, but eventually I'll want to get back up to speed on Blacksmithing.)

Coding is a language skill. It's just a way of learning phrases and rules, like any other language. The difference is that coding is often less about sentences and more about instructions; imagine if you will if your only vocabulary words were limited to different ways of telling people to go to the grocery store and pick up items, or driving to a place with directions.

I'm the (not-so) proud owner of a Comp Sci degree. I dabble in coding, and one of my ways of giving back to Habitica is via coding - but I'm not very good at the languages involved. Yet.

There's a lot of Greek-like stuff that goes into coding in the languages that make up Habitica; I've never really had much bandwidth in the past year to pick them up, and it's a loooooong jump from the basic lessons I can find online to the actual massive-sized code that is Habitica today. It's a great skill to have though, because I see a lot of jobs out there looking for developers who know those languages.

And while I told myself I'd never be a programmer, all this time at my job at the same place has meant my programming skills are a bit behind the curve. It's why I volunteered to become a Wiki editor - it makes me do stuff outside my day job.

So let's start with the... well, sort of basics.

Underneath the hood of Habitica is an API - Application Programmers Interface. Whenever you click buttons in Habitica, it runs routines inside the program, and the API exposes program calls to the world so that anyone can write a program that acts as if someone had pressed those buttons. Third party developers can use this to make programs that access Habitica without having Habitica up.

In my case, I'm wanting to do some access calls that _aren't_ available in the main Habitica GUI, because the controls don't allow them.

I have a Habit that I want to be so deadly, that if I click it, it does a LOT of damage, I was able to do this back in v2 with the Swagger UI, which had a call that sent a user task object to the database, but that's gone, so I've had to resort to figuring out how to do it myself, from the limited information available in the Wiki about it.

After trying to get Ajax to work for a day or two, I finally just went with Curl, the command line URL call tool. It involves a lot of copy/pasting, but I did eventually figure out how to get Habitica to answer my command requests; I put myself to rest in the Inn, retrieved info on my task list, and finally changed the name of a Habit. This means that I can assign that task a value of -1000, which will make it bright red for the next few weeks, and get the result I want when I click on it.

Another skill required is understanding HTTP protocol to some degree; here I have some background already, since I took classes in PHP and Javascript a long time ago. I know the difference between GET and POST and PUT, and it was just a matter of figuring out the right syntax to put it in to make requests.

Accordingly? I'm intending to make (hopefully) next Tuesday's post a tutorial on how to tinker with your character, once I get some more experimentation done, and write some procedures down.

Stay tuned.

Taldin (talk) 00:23, August 31, 2016 (UTC)