Something Something as a Service
Tags: portfolio
Published: 2021-11-15 18:20:57

# Something Something as a Service (and how it helped me do something dumb).

I am fascinated by the plethora of 'as a Service' services out there. Software as a Service, Analytics as a Service, Backend as a Service, Infrastructure as a Service, Transportation as a Service (LOL), and literally thousands of other made up terms to describe things that already maybe had a name. (Transportation as a Service == Taxis? Buses?). I didn't fully understand why the 'as a Service' paradigm was necessary until I found one that truly spoke to me. 

Behold, [Fuck Off as a Service](https://www.foaas.com) (FOaaS). This is a REST API that [this guy](https://twitter.com/TomDionysus) created to solve the very common problem of 'telling people to fuck off'. I understand the problem space so let's explore what this service can do for people like us.

## Detour: What's an API?

Let's say I'm at home and I want a sandwich. I open up my fridge and find all the things that'll combine to create my masterpiece sandwich. I then put them together myself and voila, I have made a sandwich.

Now alternatively, I could buy a sandwich from a fast food restaurant. They don't want me touching their stuff so they'll make it for me. Also, they'll do it the way they do it; there's a system. All I have to do is order the sandwich. Oh and I'll have to order it off of their menu. Yes, there are certain exceptions that can be made (no pickles or whatever), and to be honest, this analogy could probably handle that stuff too but let's just keep it simple for now. No deviations from the menu.

The menu then, is the API. I don't really need to know where they put their bread, mayo, mustard, cheese, and all the other ingredients. I'm not the one that needs to go find them and put them together. All I need is the API (I mean...menu) so that I can say "gimme a number 6" and magically after a bit of a wait, my desired result appears.

In software, an API is what you use to interact with someone elses' software solutions. They promise a certain set of results and provide you with the 'menu' that you need to order off of to get those results. Ask for things in a specific way, and your desired outcome ensues.

## Back on track: What's the deal with FOaaS?

FOaaS is a pretty simple API. It has a list of 'endpoints' that you can hit to get specific, predictable responses. All of these responses are variations of telling people to fuck off. You can test it in your browser. An endpoint is essentially just a URL that you can go to where your 'sandwich' will be waiting for you. Try it out now. Go to [https://www.foaas.com/me/enter-your-name-here](https://www.foaas.com/me/enter-your-name-here). There's behind the scenes code that inserts your name in the predetermined phrase and then displays it for you. You don't need to know how it's doing what it's doing, just that you can go to that endpoint and you will always get that result.

[https://www.foaas.com/zero/Omar](https://www.foaas.com/zero/Omar)

[https://www.foaas.com/maybe/Omar](https://www.foaas.com/maybe/Omar)

[https://www.foaas.com/cool/Omar](https://www.foaas.com/cool/Omar)

Try all of those (and sub your name for mine). 

So yes, it's pretty basic but it works and there are tons of endpoints to pick from.

## What I did with FOaaS.

So I used FOaaS and made something. It's not crazy but it was fun and it's fun to play with. Let me show you. First I have to tell you a bit about the Terminal.

This is the terminal:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rdjovsvwhv5a7ynuivn.png)

Simply put, it's an application that lets you interact with your Operating System to do...stuff. You can do all kinds of things in the terminal. When it comes to programming, it's sometimes easier and more efficient to operate within the terminal for certain tasks than use some sort of GUI so you'll often see this window open when someone's coding something.

The terminal is particularly useful when it comes to automating repetitive tasks. For example, deleting all files in a folder that end with the '.png' extension. In a very large folder that could be super tedious to do manually, but the terminal lets you do it in one line by simply typing in the following: 

`rm /some/dir/*.png`

Things like that are why it's fun to play around with (but can also make it dangerous!).

There are also some useful little commands you can call on for information. For example, if you type in `date`, you get the current time and date. Nice and simple.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pup8c891lfvt0r1sbkh1.gif)

Similarly, you can display a calendar by typing `cal` for the current month and `cal 2020` for all of 2020.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/miuo35v0034swc0eiauq.gif)


So that's the terminal and those are some very very basic commands that come with it.

## Finally, the thing!

What I wanted to do was build a new, built-in command that would work by calling the FOaaS API and would provide some sort of response within the terminal. Essentially it's a key phrase, like `date` and like `cal` that the user will call on. Additionally, in the same way the user adds 2020 to cal (i.e. `cal 2020`) to alter its behavior, the user will be able to enter parameters to hit different endpoints of the FOaaS API. So let me just show it to you in action:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ithjxrvr4puiwt2n3zd1.gif)

And there it is 😂

It's totally stupid, pretty much useless, but good for a laugh, and fun to waste time with so I consider this a huge win. You can essentially hit any of those FOaaS API endpoints and the tool will return the correct response. What this is, is an 'API Wrapper' built in Node.js. 

If you know how to do it, feel free to check out the source code here: [https://github.com/lowsound42/foaas-cli](https://github.com/lowsound42/foaas-cli) and also, feel free to download it globally via the NPM package here: [https://www.npmjs.com/package/foaas-cli](https://www.npmjs.com/package/foaas-cli) 

Whenever you're killing time between commands in the terminal, `foaas-cli` will be around to provide a quick laugh.