At work, we’re finishing the implementation of our first API using the Amazon API Gateway for decoupling the API key management, logging, and throttling from the actual backend service. This also marks our first OAuth 2.0 Resource Server, and makes heavier use of Swagger 2.0 for the entire pipeline. With all these “firsts,” I’d like to share a few notes on our setup.
Showing posts with label technique. Show all posts
Showing posts with label technique. Show all posts
Sunday, February 14, 2016
Thursday, January 9, 2014
Smart Clients and Dumb Pipes for Web Apps
After something like 8 years of coding for the web, both in new and legacy projects, across four companies and some personal projects, I've come to a philosophy on web application layout:
If you require that the client has JavaScript, then you may as well embrace the intelligence of your client-side code. Let your AJAX calls return simple messages, to be converted to a visible result for the user by code that shipped alongside that UI.
Friday, July 6, 2012
Keep the Pieces
When a low-level function is going to write out a string, for instance the To header of an email, I often find myself tempted to “just” pass down strings. Often, I find later that I would rather have the header in array form at some intermediate level, so that I can add recipients only if they’re not already present. I’m then forced to parse the string in some manner, with that choice requiring some balance of performance and correctness. (It’s tempting to make code deal only with the subset of the RFC you think you’ll need.)
If this happens more than once on the way down (“some errors should email us admins if we’re not already involved in this transaction”), it gets even worse: build original array, reify to string, {parse, modify, reify} × 2. Whereas just handing the array down through looks more like build, modify × 3, reify and send.
Letting the lowest layer put the data on the wire in the format the wire requires can also be more robust: if there are only Bcc recipients and the To address is “Undisclosed-recipients: ;” then checking whether To is empty loses its simplicity: it can have a non-empty value and yet not have real recipients. Also, nobody at the higher layers has to care whether your addresses are actually separated by comma or by semicolon.
Finally, this lets you push down basic cleaning like calling
If this happens more than once on the way down (“some errors should email us admins if we’re not already involved in this transaction”), it gets even worse: build original array, reify to string, {parse, modify, reify} × 2. Whereas just handing the array down through looks more like build, modify × 3, reify and send.
Letting the lowest layer put the data on the wire in the format the wire requires can also be more robust: if there are only Bcc recipients and the To address is “Undisclosed-recipients: ;” then checking whether To is empty loses its simplicity: it can have a non-empty value and yet not have real recipients. Also, nobody at the higher layers has to care whether your addresses are actually separated by comma or by semicolon.
Finally, this lets you push down basic cleaning like calling
array_unique() into the lowest level, meaning each modification along the way can quickly append and trust the result will be safe on the wire. All those layers become more concise and readable.
Wednesday, November 23, 2011
REST and RPC: Not Actually Antonyms
Last month found me writing a rant about REST and the shortcomings of interpreting it as "REST = HTTP+HATEOAS". I submerged myself into some writings of Fielding, and took some time for reflection, and I've found one of the sources of my problems with "REST". (Another.)
This problem is that there's too much writing on the web that attacks "RPC systems" as the logical opposite of REST, and I took this assumption unquestioned.
This problem is that there's too much writing on the web that attacks "RPC systems" as the logical opposite of REST, and I took this assumption unquestioned.
Subscribe to:
Posts (Atom)