Sometime around last year, I found myself writing more and more REST interfaces. Sometimes, the client wanted to expose data this way, and sometimes I found I couldn't bear to click the mouse 10 times every time I needed to do something as simple as clocking a job in. All these pressures forced me to start playing with the idea of abstracting the data calls out of all this messy interface business.
I found that the biggest pain was just getting the thing set up. In Ruby or Python, there was always a great deal of application setup and persistence setup. I found that in lots of cases, I had lost interest before I got to write any code.
Discovery of Teapot
I asked around on the Pharo mailing list about writing something with Zinc, and someone pointed me in the direction of Teapot, the existing REST server.
I dug around, and found that this was impossibly simple to implement, other than the bit of creating a the initial routes and error messages to get rolling.
Last night, I was starting to thing about the Internet Radio Database, and halted and checked in the program before I got any further, I imagine that this will be a good starting point of anyone, and will allow me to pick up here for all future projects.
I invite you to check it out, kick the tires, and let me know if you have any questions.
Rather than regurgitate the (great) information already available, I will point you in the direction of the articles that got me started:
- First up, you can find my repo for this project on Github.
- Check out Skrishnamachari’s Blog for a great overview.
- Kenneth Eng wrote a super detailed post on creating a real app.
- Of course, check out the author’s site for a whole lot more info. Make sure you grab the library files for a tutorial on which I based this template.
Here’s a the original test from my repo, for reference:
Pharo / Teapot REST Template
This is really just a personal itch I needed to scratch, but I am thinking it might be helpful to lots of other people interested in playing with the Pharo / Teapot packages.
This package will set up a very basic, very complete REST server. All you will need to do is add some routes and act on those actions.
I built this to allow me to quickly map out REST implementations without having worry about all the other things (persistence, etc) that can be worried about much later (if ever).
You will need to have Teapot installed or part of your project. This will also install Zinc and allow you to run tests and otherwise goof around with your server.
If you are new to teapot, make sure to checkout the teapot entires that are added into your Tools Menu
There are lots of added goodies that will be of help when testing your system.
Setting up your REST server
While this is a super simple REST server in that it only has one route and one error message, it's amazingly complete. to fire up the server, and test its functionality (other than running the test), you can do:
|server| server := RestServer serveOn: 8800. (ZnEasy get: 'http://localhost:8800/test_route') entity string.
Now, All that remains is to fill in the routes and go nuts.
Sign up for my weekly mailing list and a chance to win a vinyl LP from my collection every other week!