3 Tips for Designing RESTful APIs
There are countless books, websites and other resources that talk about how RESTful APIs should be designed. So naturally I have to add to the pile.
There are countless books, websites and other resources that talk about how RESTful APIs should be designed. So naturally I have to add to the pile.
Our fancy new RESTful API does have a endpoint POST /searchPosts
. Now we are sad as it means we aren't really doing REST at all. Let's see what we can do about that.
A pet theory of mine is, that there are three stages every programmer goes through throughout their career. Maybe they sound familiar to you.
I guess there's something to learn in anything. During the last few month I was thinking about what programming has taught me. When the notion of "it probably made me a better person" popped into my mind, I was pretty surprised, to say the least.
Here's a thing I don't like: People asking me stuff like Hey, do you have time on Saturday?
while they want to ask Hey, I'm moving. Can you help me haul all my stuff up and down 22 floors on Saturday?
I have no way knowing what they want until I gave an answer (or asked why?
).
There seems to be a lot of discussion going on about TDD being dead these days. Here's my two cents concerning the matter.
Update: Sadly Rainer, who I considered more than a client, died much too early on the 26th of October 2013. I know he will be missed.
What does web development mean? Usually you build some software that gets data out of some database converts it to HTML and sends it to a browser. Usually that software has to handle the other case, too: Receive input from a browser, make sense of it and write the data into the database. There’s your average web project.
In a recent Django project I had to work with Postgres views quite extensively. The problem is that while South does a great job handling model related stuff, you’re on your own when handling views and other database level stuff. So I thought I’d share the simple/simplistic solution I came up with.
The other day I realized I carry my MacBook most of the time in my cheap carrying bag instead of my super sexy notebook bag. After I thought about it for a few minutes I had the solution: the 80% use case.
Recently I submitted my post How to make a better analog watch to Hacker News. My idea was thwarted, of course (I got the feeling I didn’t describe the idea very well, though). But one comment really made me ponder how to break out of the this-is-the-way-it-is-done thinking.
So you probably heard about the new iPhone by now. And perhaps you are one of the many people that said something along the lines "Meh, so it's just the iPhone 4 with upgraded hardware and that gimmicky feature which allows you to talk to your phone.” You probably are failing to see the point because it’s too big.
Have you ever thought about the difference of digital watches versus analog ones? I'll tell you: Digital ones are better at their job and here's why.
Here's a hint for you: You are probably putting your Django template files in the wrong place.
Update 2012-11-07: My uni decided to put the schedule and room information behind a login so I my scripts can no longer access those. As such the project is pretty much dead. This is especially sad since the tools the uni offers are - let's say lacking.
Many battles have been fought about how to indent. And finally it's my time to beat you around the head with my opinion. Here we go.
These days I'm getting more and more frustrated by my fellow students. It seems everybody is trying to get through with as little work as possible and those who are at least motivated are very reluctant to learn any new languages/technologies.
Yeah well the other day I got me one of those shiny modern MP3 player thingies — namely a Sansa Clip+. Really nice gadget and all but whenever I copied some of my OGGs on it it would hang during the library update.
The other day I needed to decorate a method with a decorator class that knows about the owner of the method meaning the instance. This works as expected with function decorators:
Need to shorten your URLs like Google does? Something like http://example.com/some/really/long/path/ to http://example.com/.../path/? Here's my simplistic approach:
Since I'm mostly working on various Django projects I am working with virtualenv/virtualenvwrapper a lot. It allows to encapsulate environments and keep them identical across all servers your app will run on.
Last week I had to implement a customized RSS feed in Django for the first time. Sounded like a fun project to me until I had a look at the documentation which is… well let's just say it's not as good as the core documentation.
The other day I was wondering what the difference is between work and the screwing around I do at home for fun. After putting quite some thought into it and coming up with the typical explanations like not getting paid, being able to choose what you want to do and stuff it struck me: There are no deadlines for stuff.
So for quite a few months I was pretty sure having HTTPS on multiple domains with the same IP was a no-go on nginx. I was wrong.
My search for a nice and easy tumble blog I can host myself lead me in a pretty straight line to Gelato CMS. But when I looked into the database after I had been playing around with it a bit I saw that all umlauts (äöü for you non-umlaut knowing ignoramus people) turned to garbage.
Image you are running a staging system for your Django project on which all the testing for the production system is done. You are using a dump of the production database to have some actual data you can play around with. And you have this one/many function/s in which you send email to some/all users. They probably will not be happy to get all those emails from your staging system while not having the slightest idea what's going on.
And all of a sudden I got this on my Gentoo server no matter what I tried to emerge:
Just read this article which gives a description on how to archive Twitter stuff with Python. I saw the code and thought 'heck why so complicated?'.
I'm talking about the little images - not the star people everybody goes crazy about. Anyway, after having used the Silk Icons for what seems an eternity (they are good you know) it was time for something new.
Alright after about a whole day of near-continuous downtime I finally found the bug that I overcame few months ago already. I'm using nginx as proxy to Django per FCGI. Now after upgrading nginx the site started to misbehave. No matter which location I tried to access I always ended up on the index page.
These days I'm quite amused by all the rage about HTML5 and CSS3. Don't get me wrong I absolute am for it. There are so many hacks and 'techniques' around to archive stuff that should just be in there that sometimes people seem to forget that it could be different.
In search of a workable search pluggable for Django I played a bit with Django Sphinx some time ago. Its potentially nice but involves a lot of work to configure Sphinx itself. So it was difficult enough to configure for me to drop it.
I've been playing with Selenium at work for some time now and the more I saw of it the testing framework the more I was impressed.
After I see more and more sites offering OpenID authentication and more and more people using it I finally got interested enough to see for myself what it all is about. I didn't do so earlier because I just am getting a little paranoid and OpenID just seemed to me like giving some big, faceless company access to virtually anything I do on the web. Turns out that is not the case.
I had to write a multi-object edit table the other day for a Django project and as such I dove into the FormSet Documentation. Django's documentation is really good usually but the part abut the FormSets was a bit of a letdown.
So the other day I started to look for tools that let me use variables in CSS. This mainly was because it really gets old to copy paste the same colors over and over again. Thanks to Twitter soon I was pointed in the direction of LESS.
Have you ever read The Last Question by Isaac Asimov? If not please do because I think Asimov is describing the not so far-off future there.
I just read this article: http://www.usabilitypost.com/2008/09/05/drop-ie6-support-give-people-a-reason-to-upgrade/.
If you ever need to remove a cache fragment that has been created by the cache template tag do like so:
So a combination of two Tweets made me go to thinking mode the other day. The first one asked: "What would you do/think if Twitter didn't exist tomorrow?" And the second one: "I'll leave Twitter in the coming weeks - 140 characters aren't enough."
So these days I spend a lot of my workday trying to get a Django app up to speed that... wasn't exactly written with performance in mind. Here are a few things that helped me speed up that thing (all without going down to SQL level):
So the other day I wondered if it wasn't pretty cool if Django models would have something like members that are in fact raw queries. On the bus home it occurred to me that this functionality already exists. Just add a custom manager to a model which always returns querysets with extras.
Well that's what I was told the other day. So I came up with the proposal to misuse django-better-chunks as a makeshift database based i18n system. But since I made quite a few changes to the code and wrote some utility functionality I thought 'heck somebody might need just this'.
So since right now I'm playing the performance optimizer again I searched for a nice profiling/debugging tool for Django. Loads of snippets I found, loads of middleware, loads of scripts and stuff. And then a colleague of mine said "you know I always used something called Django debug toolbar or something". I'm like "alright let's google for it and see if it's any good".
So I will say this and then I'll be out of the whole Mac/PC flamewar again.
Alright, after some out-time mainly due to work-overload in the last few weeks (and the general laziness of my person) let's see what we can do.
This bit me majorly yesterday. Nobody tells Bash when the current folder is renamed.
Now this is what you do all the time to strings in Python:
Now here I got another pearl. It bugged me to no end that one cannot have a ModelForm and override only certain attributes of a certain field without having to overwrite the whole field with all of its default attributes. Well, seems that is actually possible, like so:
Just a little reminder for myself, since I never am able to recall how to ignore stuff in Subversion:
Since I often have to do with date and time arithmetic, Python dateutil seems quite interesting. Loads of additional features concerning date and time stuff. I have play a bit with it sometime.
One idea that I encountered and that I just didn't like right from the start is this one:
If you are into web development you probably have to code some HTML from time to time if not constantly. And if you are anything like me you always try to get your HTML as valid as possible (I mean, come on - there are cases when you just say 'screw it'). So while the W3 Markup Validation Service is nice and stuff, its not really what you call convenient.
Okay if you - unlike me - did actually read the documentation of the Python traceback module you probably know that what I wrote here can be archived much easier if you just do this:
Django is nice, I think I have made my point clear on that. As a framework it lets you some truly short code that does quite a lot. It's convenient. But you should be careful to not let yourself fall into the trap of convenience. Here's an example of what I mean:
Alright so you're one of those web developer/web designer guys, too? And you're on a Mac and still need to test those websites on the loathed abomination known as Internet Explorer? If you don't want to shell out any money to be able to do what you probably hate here's a quick guide:
Today while happily hacking away at my Python code I found myself in the following situation: I needed the traceback of an exception while not wanting the whole app to exit because of the exception being raised.
If you are one of those people that totally are into life feeds/streams of... well anything then you will perhaps be interested in Sweetcron. It's one of those hip lifestream tools - but if you're a bit paranoid about your personal data (like me) than you probably would rather host something like that yourself.
Okay this is exciting news. My favorite Django migration tool South has received a major update. I just stumbled over some changes to the documentation when I browsing the site the other day.
So the other day I bought VoodooPad. Yes I actually paid money for it. If you knew me you would know that means something.
So you're coding for a living and every few minutes there is this snippet of code you would like to keep around just in case but don't know where to put it? Or perhaps you're one of these people that have great ideas constantly but just never got a piece of paper?
For all of you who like me are getting a bit paranoid about Google these days and still would like to have the nice stuff that a tracker like that provides I got one nice tool for you: Piwik. This thingie tries to be the free, open source Google Analytics (they actually say that) and it actually comes pretty close for its price.
Okay I couldn't come up with a witty title this time - sue me. But nevertheless I have a real treat for you today. Sure we all use Photoshop and there surly isn't anything that can compare. Yeah, yeah we know that. But what about those times you fire up the big beast that Photoshop is just to edit some tiny little graphic or need to come up with a simple icon?
Using Apache and Django is throwing SuspiciousOperation Exception in your face and you have no idea why? Chances are you are using absolute paths. Django doesn't like that. It expects you to be a good boy/girl and put all your stuff under MEDIA_ROOT with relative paths. Everything else is perceived as suspicious behavior it seems.
I think my new favorite Django-pluggable is django-compress. Since I still haven't figured out how to install the YUI Compressor globally, I now can leave it all to the Django-app.
Really nice and handy tool: ack Bundle. It's about a bangzillion times faster than the ordinary 'Search in Project' thing of Textmate. That probably doesn't make it the optimal tool for your daily office work.
Funny that I didn't know until a short while ago that my favorite text editor TextMate supports plug-ins. Even funnier: With ProjectPlus the lighty light TextMate almost becomes a mini IDE.
I've been searching for a Mac app that allows me to see where all my precious hard drive space has gone. There is quite a nice little app called SequoiaView which is really good at that task — sadly it's not available for my beloved Mac.
I find it interesting that everybody that had the chance (was forced) to work on a Mac for a period of time buys one sooner or later. Most probably do cause these thingies are really good lookin' - I'm not deluding myself there. But I also think that once used to Mac OS nobody really wants to go back to Windows that soon.
Somehow I find it funny that so many web designers and agencies advertise their services with 'pixel perfectness'. That probably would mean the site looks like the Photoshop template - down to the pixel. Just like with print stuff where you define positions with a precision of three positions after decimal point and it will look exactly like that when it's done.
Sometimes I don't get people: "Oh heck what was my ICQ again? Could you give it to me?" Or how about "Oh... what was my login and pass for my web space again?"
Got multiple Macs and don't feel the need to spend money on .Mac? Unison to the rescue! This little tool lets you synchronize directory trees and acts like its some kind of simple CVS, meaning it detects conflicts (for example when a file has been changed on multiple Macs) and lets you resolve them.
Okay so after taking a few hours to find out how to get a unique SlugField into the database per South here's what I found out:
Switching the database is quite fun with Django. In my case I'm slowly migrating my sites from MySQL to Postgres.
Rails is great. At least better than anything I know that is done with PHP. PHP is really some nasty stuff. Seems like more and more people realize that and jump on the Ruby on Rails band wagon. Well since everybody else says its that great it has to be, no?