Friday, October 23, 2015

RESTful APIs and RMM

I was putting my notes together from class about REST APIs to help someone out, but I found out I misunderstood what they needed help with before I finished but after I had written all this so here, enjoy, maybe you'll learn something.


Measuring RESTfulness and creating a HATEOAS REST service.

When you measure RESTfulness we have a scale that’s called Richardson Maturity Model. The scale ranges from 0-3 where 0 is not RESTful and 3 is HATEOAS.

0 on the scale of the RMM is a simple URI with the method in the request. This is the level SOAP is at. It’s not restful.

1 on the RMM scale is when you’re dividing the URIs on a resource level, instead of the URI /API/getAllTheThings we now split the things up in the URI not in the request body; /API/things/thingid, however, we’re still putting the request method in the request body.

2 of the RMM scale is when you’re on top of dividing your URIs on a resource level start using the HTTP protocol’s GET, POST, PUT and DELETE and the appropriate response codes:
100 - Continue
200 OK (it’s common practice to add the text OK to the responsecode) - Everything went well.
404 - File Not Found
418 - I’m a Teapot (and I can’t brew coffee)
500 - Internal Server Error

Pretty much the
  • 100 codes are informative,
  • 200 codes are success codes,
  • 300 codes are for redirects,
  • 400 codes are user/client errors and
  • 500 are internal server error.
Read more about the different responsecodes at https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

3 is when you Reach HATEOAS and is the last on the RMM scale. You’re done, your webservice is - in theory - the best thing ever. Have a cup of coffee and high five your colleagues (or cat) and everyone who’s ever gonna use it.

So what is HATEOAS?

HATEOAS stands for:

Hypermedia - You had better look this up; hypermedia, hypertext and the other hypers are by legacy all the hype!
as
the
Engine
of
Application
State

To crudely sum it up; media (text, images, video, audio) is what’s supposed to drive the interaction between the client and server. The idea is to let a client know how to interact with your API without any manual or prior knowledge about the API. Just like how it works when you’re visiting a web GUI; you don’t need to know what URLs will take you to the next part of the website to go there, there’s a link, you click it and you’re there! Click here for free pictures of kittens!

Here’s a non HATEOAS JSON response from the API at the URL /API/messages/17
{
   “ID”: 17,
   “message”: “I love pie.”,
   “created”: “2015-10-12T10:25:00.000”,
   “author”: “25”
}

That’s the object of information that I wish to retrieve. But it really doesn’t say anything about the rest of the API.

This is a response from an API qualifying for HATEOAS:

{
    “ID”: 17,
    “message”: “I love pie.”,
    “created”: “2015-10-12T10:25:00.000”,
    “author”: “25”,
    “links”: [
        {
            “href”: “/API/messages/17”,
            “rel”: “self”
        },
        {
            “href”: “/API/messages/17/comments”,
            “rel”: “comments”
        },
        {
            “href”: “/API/profiles/25”,
            “rel”: “author”
        }
    ]
}

This response offers the information the client/user need to orient themselves while using the API.

But wait, there’s more!

Let’s say we’ve been good devs and made an API with a URI to the messages, the individual resource of a message, the profiles, the profile of the author, the comments and the individual comment like so:

/API/messages/
/API/messages/{nn}
/API/messages/{nn}/comments/
/API/messages/{nn}/comments/{nn}
/API/profiles/
/API/profiles/{nn}

Of course all of these maps back to the resources and objects in the code. How would we do with them HTTP methods in the requests?

/API/messages/ is the URI

Wednesday, October 14, 2015

Learning illustrator

Since it's about time that I make myself a CV to hand out to the companies I hope will wanna hire me full-time as a junior dev I thought I'd learn Illustrator.

This is how it's going:


Now that I have a screen that's actually larger than an A4 paper, dafuq man?

Saturday, July 4, 2015

Things I wish someone had told me.

If you're new to Java or programming in general, here are a few things that I wish someone had told me before I figured it out the hard way:

Databases are server software. If you're making a desktop application, do mot use databases to store information; write to a file if there's something you wish to save. Most databases don't hide inside your jar/application and get installed along with your application; you'll have to tell the user to download, install and set them up so that your application can access them. It's just not how you get your application running...

By all means, use JOOQ over Hibernate when you're getting it on with a ORM framework for your application, but make sure that you NEVER EVER EVER EVER forget that whatever folder you set JOOQ up with will be completely cleansed of any files not generated by JOOQ. This includes your own personalized record objects.

If you're using maven, the code in the POM where you'll be putting your  JOOQ generation file will look something like this:
<target>
    <packageName>com.company.projectname</packageName>
    <directory>src/main/java</directory>
</target>
 Make sure you change the package name to something like com.company.projectname.jooq or it will remove EVERYTHING in your root project folder.

If you accidentally set JOOQ up with your project root, you'll be glad to have read the next point:

Taking your time to interrupt yourself to commit your work to git may feel annoying and distracting; it's breaking your flow! But I promise you, IT'S WORTH IT! Whenever something's running as it should, tests come back OK and all of that, commit it! If all hell breaks loose because JOOQ was set to your root folder, you'll be thanking yourself! Not to mention the even more important thing; it will ease tracking your own code. Git offers you the amount of control to even commit single lines inside of your files. Use it! Because one day you'll be looking at your commit dumps and wonder when the heck you changed what that is now bugging your code apart. It will happen.

Learn to version your code from day one. Just do it.

Don't ignore project structures, thread safety, unit testing, Dependency Injection (DI), multi-layering your architecture, proper class separation, separation of concerns or  how to avoid side effects. As soon as you can, you need to star learning how to implement these things. They matter, they are important and you will thank yourself for learning it the right way straight away, not after you learned how to code the thickest pasta github has ever seen. You're a programmer, not a chef.

For now the last, but not least, advice I have for you:

The programming communities are very helpful and as long as you're aware of the fact that the help they give you is incredibly invaluable and something they give you for free. Demanding help is gonna get you about as much help as stabbing yourself in the middle of a forest will give you.

Happy coding everyone!

Friday, July 3, 2015

Fortunate one!

I haven't written much here lately as I've been pretty busy as I managed to land a job which I work at while I study. It eats all of my time but I'm very happy and fortunate. Working while I study is kinda exactly what I thought it would be; I'm learning so much! So many things I never thought existed! I'm not doing as much Java as I'd hoped but what does it matter when I get to learn and try so much other things that are so much fun!

I've only been a developer for 9 months and it's yielded so much for me and I feel incredibly lucky and happy. I earn money on my hobby! On what I love to do!

Now if you excuse me, I have lots to learn so enjoy this random quote:

Teach a man to google and he'll be developing for life. Teach a man to have you google it for him, and you'll be googling for him for the rest of his life.

Friday, April 3, 2015

Bashing people for not using Linux is like bashing people for living in apartments

First off, let's start with everything that's great about houses and linux;
There's a lot of freedom. A LOT of freedom. You can remodel and build whatever you want in it. Want a second kitchen? BAM! Just build one and you got one! You can hire any contractor you want for whatever job you want, you're not restricted by your landlord. You can be as noisy as you want, you're not dependent on anyone else but yourself. There are no secret processes going on that you aren't aware of unless you chose to stay ignorant. Most people who know what they're doing would probably prefer to live in a house.

Hardware limitations transfer to your property's limitations; there may be restrictions about adding little huts or building out your house, but within the limitations, you can do whatever you want, and that is a lot more than when you live in an apartment.

Sometimes it can even be a lot cheaper to live in a house than in an apartment. But if you have to build a house, learning Linux takes time, and time is money. Ubuntu is like a module house or a suburban terrace.house. It's a little bit easier to live in and maintain, but it's still a house. You don't spend as much time building it. But you also loose a little of your freedom. Not to mention, nobody is going to fix things for you. There's no landlord to call about that dripping tap or the hole in your roof. You are your own boss here for the better and worse.

Apartments, like windows and macOS are easily available; they often come with your device, just like apartments are a natural part of a city, whereas houses usually are a bit away from the city core or any city for that matter. There are a lot more options where software translates to stores and services; the demand is higher and therefor the supply. They're cheap, you don't build anything really. With the landlord's permission you may be able to remodel your kitchen, but why would you? When the time comes, the landlord will do that for you. Things run smoothly, but you don't have that freedom you would have in your own house.

For some people, getting a house or a Linux computer is equally hard; there may not be houses where they need to live and if you don't have anyone to help you learning Linux, some might not be able to learn it at all.

For the mass who want the conveniences that a city gives you, an apartment is the best choice. And it only makes sense that an architect or property owner knows how the apartments work in order to develop them. Even if you live in a house, you'll probably still at least have an office in the city.

Sure, houses do have their own services too; you'll find a local store that has the essentials, but it's far from all the luxury you would have wanted. If enough people buy houses in your area, then of course the supply of services becomes greater too, but eventually, they'll tear down the houses and build apartments there too as it becomes a city rather than a village.

Linux is not bad, I love Linux, but it just doesn't make any sense to me to bash people just for using a certain OS. When you know your shit, Linux is awesome! But if you don't know your shit, if you can't build whatever you need when there's no supply of it, you're kinda doomed.

I do agree however that every developer should try to have at least one Linux machine, or a dual boot. Just like I do kind of believe that every developer should own a device running the OS they are developing. Unix is great to learn! But not everyone is capable of building their own house from the very basics.

Saturday, March 28, 2015

Relationship blogging

private class SignificantOther implements Adorable {
        private void adorable(IceCream nom){
            nomNom(nom);
        } 
}

private class Me implements Weak{
        public IceCream give(){
            IceCream nom = Cupboard.get("IceCream");
            return Nom;
       }
}

Friday, March 27, 2015

Working hard or hardly working?

Well, I'd say I've been working hard lately. I've learned so much and things are becoming increasingly fun. Not to mention that I just started shallowly network for a job, and it's been way over my expectations result wise. I've been to two interviews for one company and I met one guy who wants to help me network with his contacts. And all this without showing a single line of code. We've talked code though, a lot of code. I love talking about code, but not as much as actually coding. And that is why I want to start working!

Also, the idea of having a job brings me one step closer to having the money to get me my optimization coding machine 3000:
Yes, it's a big thermos. 2,5L should be enough until about lunch.