{"id":4132,"date":"2017-02-23T17:54:09","date_gmt":"2017-02-23T17:54:09","guid":{"rendered":"https:\/\/www.ckl.io\/?p=4132"},"modified":"2022-07-01T17:44:04","modified_gmt":"2022-07-01T17:44:04","slug":"api-design-think-first-code-later","status":"publish","type":"post","link":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/","title":{"rendered":"API Design: Think First, Code Later"},"content":{"rendered":"<p>As a software developer, I know how hard it is to contain the urge to start coding as soon as we can. After the first sprint planning, our fingers \u2013 uncontrolled, hungry creatures \u2013 want to start smashing the keyboard, translating our ideas into code fastly and furiously.<\/p>\n<p>Despite how great we feel while developing, it&#8217;s always a good idea to take a step back, especially when building something that could be used by many different users \u2013 like an API is. A. In this post, I\u2019ll show you why and how to design a properly-thought API.<\/p>\n<p><!--more--><\/p>\n<p>API is a generic term to define an Application Program Interface, in other words, how a user (human or machine) interacts with a program. In the web development world, an API is generally a website with a collection of endpoints that respond to client requests with structured text data.<\/p>\n<p>Another concept that&#8217;s widely used and discussed by web developers is the one of a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\" target=\"_blank\" rel=\"noopener noreferrer\">RESTFul Web API<\/a>. It was defined by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Roy_Fielding\" target=\"_blank\" rel=\"noopener noreferrer\">Roy Fielding<\/a> as an architecture style that provides a well-established communication protocol between client and server. It outlines some constraints: stateless communication, respect of the underlying technology (generally HTTP) and the use of <a class=\"zem_slink\" title=\"HATEOAS\" href=\"http:\/\/en.wikipedia.org\/wiki\/HATEOAS\" target=\"_blank\" rel=\"wikipedia noopener noreferrer\">hypermedia as the engine of application state<\/a>. In other words, it proposes some patterns for building a web API. For simplicity&#8217;s sake, I&#8217;ll be referring to Web APIs simply as APIs throughout this post.<\/p>\n<h2>One JSON is worth a thousand words<\/h2>\n<p>Let\u2019s see an example of an API response:<\/p>\n<pre><code class=\"language-json\">\n{\n  \"data\": [\n    {\n      \"story\": \"Jonatas Baldin was writing a blog post.\",\n       \"created_time\": \"2017-15-01T00:02:57+0000\",\n       \"id\": \"624510964324764_1046909755418214\"\n    },\n  ]\n}\n<\/code><\/pre>\n<p>This snippet of data, called <a href=\"https:\/\/www.w3schools.com\/js\/js_json_intro.asp\" target=\"_blank\" rel=\"noopener noreferrer\">JSON<\/a>, is an example of how a smartphone sees a Facebook status message, gathered from the <a href=\"https:\/\/developers.facebook.com\/docs\/graph-api\" target=\"_blank\" rel=\"noopener noreferrer\">Facebook API<\/a>. Pretty neat, right?<\/p>\n<p><span style=\"font-weight: 400;\">Now imagine that you are an engineer at Facebook, responsible for this API. You wake up one day and decide to change the <\/span><i><span style=\"font-weight: 400;\">id<\/span><\/i><span style=\"font-weight: 400;\"> field name to <\/span><i><span style=\"font-weight: 400;\">message_id<\/span><\/i><span style=\"font-weight: 400;\">. Well, this small change could break Facebook. For real. All devices that depend on the previously-defined structure would now stop being able to collect and display the content to the user. Definitely not a great day at work.<\/span><\/p>\n<h2>The good, the bad and the ugly<\/h2>\n<p><span style=\"font-weight: 400;\">A bad API design \u2013 or the lack of it \u2013 will, sooner or later, cause all kinds of trouble:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Absence of consistency<\/strong>: once an API grows, the endpoints tend to be created just to fulfill immediate needs.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Difficulty to scale<\/strong>: there\u2019s no reference when troubleshooting an endpoint.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Hard to learn<\/strong>: a steep learning curve to consume data from and develop the API.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Performance issues<\/strong>: throwing unplanned API code usually creates performance bottlenecks on the long run. <\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>APIs tend to be forever<\/strong>: it\u2019s always better to get it right at the first chance.<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4157 size-full\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/ezgif.com-resize.gif\" alt=\"sad\" width=\"300\" height=\"300\"><\/p>\n<p>An API is a contract between your application and its users. It can\u2019t be changed abruptly without causing chaos for those who already signed it and it shouldn&#8217;t be built without forethought. This is where <a href=\"https:\/\/en.wikipedia.org\/wiki\/Design\" target=\"_blank\" rel=\"noopener noreferrer\">design<\/a> enters: the creation of a plan or convention for the construction of an object, system or measurable human interaction.<\/p>\n<h2>First things first: Let&#8217;s talk HTTP<\/h2>\n<p>Before diving into API code, let\u2019s get a glimpse of the <strong>Hypertext Transfer Protocol<\/strong>. HTTP, as the name suggests, is used to transfer data on the web. It has a set of rules on how clients and servers should exchange information. Its main components are:<\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>URL:<\/b><span style=\"font-weight: 400;\"> where your resources are on the web, the address of your endpoint. An example is using <\/span><a href=\"http:\/\/example.org\/users\"><span style=\"font-weight: 400;\">http:\/\/example.org\/users<\/span><\/a><span style=\"font-weight: 400;\"> to list your users.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Request methods:<\/b><span style=\"font-weight: 400;\"> the action a client wants to perform on a specific endpoint. <\/span><b>GET<\/b><span style=\"font-weight: 400;\"> is used to retrieve a resource, <\/span><b>POST, to <\/b><span style=\"font-weight: 400;\">create one, <\/span><b>PUT<\/b><span style=\"font-weight: 400;\"> and <\/span><b>PATCH<\/b><span style=\"font-weight: 400;\"> to update an existing one, and <\/span><b>DELETE<\/b><span style=\"font-weight: 400;\">\u2026 well, deletes stuff.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Headers:<\/b><span style=\"font-weight: 400;\"> contain information about the client or the server. For instance: content type (format), method, authentication token and others.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Body:<\/b><span style=\"font-weight: 400;\"> the data sent to the server or received by the client. JSON is the <\/span><i><span style=\"font-weight: 400;\">de facto<\/span><\/i><span style=\"font-weight: 400;\"> standard. <\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Status code:<\/b><span style=\"font-weight: 400;\"> a three-digit number which tells the request status. To summarize, <code>2xx<\/code>&nbsp;statuses means success, <code>4xx<\/code> means client errors and <code>5xx<\/code> means service errors. You can get a full list <\/span><a href=\"https:\/\/http.cat\/\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\"> or <\/span><a href=\"https:\/\/httpstatusdogs.com\/\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Let&#8217;s see an HTTP request\/response example:<\/span><\/p>\n<pre><code class=\"language-markup\">\n\n<b>Client request:<\/b>\nGET \/users\/1 HTTP\/1.1\nHost: www.example.org\/users\n\n<b>Server response:<\/b>\nHTTP\/1.1 200 OK\nContent-Type: application\/json\nDate: Sun, 19 Feb 2017 00:43:51 GMT\n\n{\n  \"id\": 1,\n  \"first_name\": \"Jonatas\",\n  \"fast_name\": \"Baldin\",\n  \"role\": \"Caker\"\n}\n<\/code><\/pre>\n<h2>Good API design demands good specifications<\/h2>\n<p><span style=\"font-weight: 400;\">There are some specifications to help you out when designing your API. The most used ones are <strong>Swagger<\/strong> with pure JSON, <strong>RAML<\/strong> with YAML notation and <strong>API Blueprint<\/strong> backed by the markdown syntax. I felt in love with the latter: even though it is the new cool kid in the neighborhood, it\u2019s already mature enough and delightful to work with. That\u2019s the one I\u2019ll be covering here.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">From the official website:<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">API Blueprint is simple and accessible to everybody involved in the API lifecycle. Its syntax is concise yet expressive. With API Blueprint you can quickly design and prototype APIs to be created or document and test already deployed mission-critical APIs.<\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">It\u2019s an open source, focused on collaboration, easy to learn and well-documented specification created by Apiary with <a href=\"https:\/\/cheesecakelabs.com\/blog\/blog\/building-app-phase-2-product-design\/\">design-first<\/a> in its core, surrounded by awesome tools: from mock server generators to full-feature life-cycle solutions.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In addition to Blueprint, there\u2019s <strong>MSON<\/strong> (Markdown Syntax Object Notation), which defines data structures in a human-readable way. Instead of writing manually the endpoints body data, you represent them in reusable objects. Pretty nifty, huh?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here\u2019s what you need to know to get started:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>API Name, Description and Metadata<\/strong>: describe a little bit about the API and the Blueprint version.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Resource Groups<\/strong>: group of related resources, like Users.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Resource<\/strong>: Defines a unique resource, its endpoint and action.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Parameters<\/strong>: Used in an endpoint to specify a dynamic parameter, like an ID or query search.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Response<\/strong>: The content-type, HTTP status code and body data.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Besides that, there\u2019s <a href=\"https:\/\/apiary.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apiary<\/a>. It\u2019s a collaborative platform to create, render, test and serve your API. They have a free plan for public projects and you can sign up directly from your GitHub account to create your own designs.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here\u2019s a Blueprint code sample:<\/span><\/p>\n<pre><code class=\"language-markdown\">FORMAT: 1A\nHOST: http:\/\/cakes.ckl.io\/\n\n# Cakes API\nCakes is an API used to store and consume information about the most loved Cakes here at Cheesecake Labs.\n\n# Group Cakes\n\n## Cakes [\/cakes\/]\n\n### List all Cakes [GET]\n\n+ Response 200 (application\/json)\n\n+ Attributes (array[Cake])\n\n# Data Structures\n\n## Cake (object)\n+ id: `1` (string, required) - The unique ID of a Cake.\n+ name: `Cheesecake` (string, required) - The name of a Cake.\n+ rating: `5\/5` (string, optional) - The rating of a Cake.\n<\/code><\/pre>\n<p>If you access the <a href=\"http:\/\/docs.cheesecakelabs.apiary.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">project<\/a> above, you\u2019ll see a prettily-rendered page. Now the awesome part: a mock server is automatically created for every project \u2013 look at <a href=\"http:\/\/private-b604b-cheesecakelabs.apiary-mock.com\/cakes\/\" target=\"_blank\" rel=\"noopener noreferrer\">this<\/a>! See the magic? No code was needed to make it work. Anyone with basic knowledge of HTTP and Blueprint can create a mock API and get feedback from customers.<\/p>\n<p>The example above is as simple as it can get. You can check the Blueprint <a href=\"https:\/\/apiblueprint.org\/documentation\/tutorial.html\" target=\"_blank\" rel=\"noopener noreferrer\">tutorials and documentation<\/a> to go deeper into its syntax and read the specs <a href=\"https:\/\/github.com\/apiaryio\/api-blueprint\/blob\/master\/API%20Blueprint%20Specification.md\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. Also, this is an open-source project \u2013 any contribution from the community is welcomed.<\/p>\n<p>Congratulations! Now you are armed with the knowledge necessary to design your APIs. But before you start rocking your systems, here are some little tips to keep on your toolbelt:<\/p>\n<h2>Dos and Don&#8217;ts<\/h2>\n<p><span style=\"font-weight: 400;\">We have walked a long path together, from understanding what is an API and why its design matters, passing by the HTTP protocol and landing on Blueprint API, giving you the foundation to start creating your own designs. I\u2019ll list some amazing dos and don&#8217;ts. Note that these aren\u2019t rules, just best practices you generally find on the web.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Treat endpoint actions as CRUD(L) operations<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Our <code>\/cakes\/<\/code> endpoint may have Create, Read, Update, Delete and List operations. You can construct these actions with HTTP verbs and the URL, like:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>List<\/strong>: <code>GET \/cakes\/<\/code><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Create<\/strong>: <code>POST \/cakes\/<\/code><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Read<\/strong>: <code>GET \/cakes\/1\/<\/code><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Update<\/strong>: <code>PATCH \/cakes\/1\/<\/code><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Delete<\/strong>: <code>DELETE \/cakes\/1\/<\/code><\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><b>Correctly use the HTTP methods<\/b><\/p>\n<p><span style=\"font-weight: 400;\"><code>GET<\/code> is for getting, <code>POST<\/code> if for posting. Don\u2019t use <code>POST<\/code> if you just want a list of Cakes.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>HTTP has methods, use them!<\/b><\/p>\n<p><code>POST \/cakes\/createCake<\/code><\/p>\n<p><span style=\"font-weight: 400;\">You don\u2019t need to specify the action in the URL, we already know that <code>POST<\/code> creates something.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><code>POST \/cakes\/<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Cleaner URL, also telling us that probably the other methods will work as expected, like <code>GET \/cakes<\/code>.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Singular or Plural? Plural!<\/b><\/p>\n<p><span style=\"font-weight: 400;\"><code>GET \/cakes<\/code> should return a list of Cakes, so <code>GET \/cake\/1<\/code> should return the first Cake, right? Unfortunately, no. Even though it makes sense in our language, it will just confuse clients and developers with one more endpoint.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Searching, ordering, limiting? Use query parameters!<\/b><\/p>\n<p><span style=\"font-weight: 400;\">This feature allows you to specify some filtering on List endpoints, here\u2019s an example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><code>GET \/cakes\/?name=apple<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">If implemented, should list all the Cakes with apple in the name.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><code>GET \/cakes\/?name=apple&amp;rating=4<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can also concatenate parameters with &amp;, search for apple and a 4 rating.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Return. Errors. With. 4xx.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">If you want to take just one thing from this article, make sure it\u2019s this one: everybody freaking hates a response with HTTP <code>2xx<\/code> and a message of error! Use the correct codes:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>401<\/strong>: Unauthorized access, where the authorization process wasn\u2019t done correctly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>403<\/strong>: Forbidden access, the client is authorized, but has no access to the resource.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>404<\/strong>: The famous not found, indicating the resource is not available.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Describe your errors with clarity<\/b><\/p>\n<p><span style=\"font-weight: 400;\">When something fails, inform the client about what happened and how it can recover. Here\u2019s a nice way to do it:<\/span><\/p>\n<pre><code class=\"language-json\">\n{\n  \"error\": {\n    \"type\": \"Authentication Error\",\n    \"details\": \"Authentication could not be established with the given username and password\",\n   }\n}\n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Everyone understands that.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>I\u2019m a teapot<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Implement the <\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Hyper_Text_Coffee_Pot_Control_Protocol\"><span style=\"font-weight: 400;\">status 418<\/span><\/a><span style=\"font-weight: 400;\"> in a HTTP response. You know, just for fun!<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Resources are like object classes<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The API endpoints will respond with a resource representation. Think about these resources as object classes, they then to represent things in the real world.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">I could write a lot of tips here, but this post would become a book. And there\u2019s already a good one, <\/span><a href=\"https:\/\/apisyouwonthate.com\/\"><span style=\"font-weight: 400;\">Build APIs You Won\u2019t Hate<\/span><\/a><span style=\"font-weight: 400;\"> by Phil Sturgeon.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Trust me on this, using a Design-first philosophy will give you better nights of sleep. Here are some advantages and characteristics of a good API:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Talk to your customers<\/strong>: understand what they need, not what they want. An API without clients is nothing but a bad API.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Easy to<\/strong> use: endpoints, resources and output data should follow the same structure as much as possible.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Hard to misuse<\/strong>: if a bad request is made, return an error and be informative.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Simple is better than complex<\/strong>: as a Pythonista, this is carved into my heart. Simple things are easy, in every aspect.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Use your API before implementing<\/strong> it: create a mock server to get a feel of the end result. If you can, talk to your future customers and ask their opinions.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Be resilient<\/strong>: when a crash happens, informe why and how to handle the situation.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><strong>Test everything<\/strong>. Really. Write tests for every endpoint, method, parameter, input and output data.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">At the end of the day, your API is a new little language you\u2019ll have to teach to other people.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4158 size-full\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/giphy-3.gif\" alt=\"thumbs up boy computer\" width=\"316\" height=\"223\"><\/p>\n<h2>I\u2019m almost done, just some references<\/h2>\n<p><span style=\"font-weight: 400;\">If more tips could fit a book, talking about all aspects of API Design would fit a library. I\u2019ll leave you, my patient reader, with some amazing references on further topics:<\/span><\/p>\n<ul>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\"><span style=\"font-weight: 400;\">HTTP on Wikipedia<\/span><\/a><span style=\"font-weight: 400;\"> &#8211; a good reading about the Hypertext Transfer Protocol.<\/span><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=aAb7hSCtvGw\"><span style=\"font-weight: 400;\">How To Design A Good API and Why it Matters<\/span><\/a><span style=\"font-weight: 400;\"> &#8211; a talk by Joshua Bloch Java APIs, but the concepts apply to the web as well. <\/span><a href=\"http:\/\/zoomq.dn.qbox.me\/ZQCollection\/presentations\/Howto-Design-a-Good-API_Why%20it%20Matters.pdf\"><span style=\"font-weight: 400;\">Here<\/span><\/a><span style=\"font-weight: 400;\"> are the slides.<\/span><\/li>\n<li><a href=\"http:\/\/shop.oreilly.com\/product\/0636920028468.do\"><span style=\"font-weight: 400;\">RESTful Web APIs<\/span><\/a><span style=\"font-weight: 400;\"> by By Leonard Richardson, Mike Amundsena and Sam Ruby &#8211; learn everything about &nbsp;the web, HTTP, hypermedia and domain-specific designs.<\/span><\/li>\n<li><a href=\"https:\/\/spring.io\/understanding\/HATEOAS\"><span style=\"font-weight: 400;\">HATEOAS<\/span><\/a><span style=\"font-weight: 400;\"> &#8211; one of the constraints of RESTful APIs.<\/span><\/li>\n<li><a href=\"http:\/\/jsonapi.org\/\"><span style=\"font-weight: 400;\">JSON API<\/span><\/a><span style=\"font-weight: 400;\"> &#8211; a specification for build APIs in JSON.<\/span><\/li>\n<\/ul>\n<h2>Wrapping up<\/h2>\n<p><span style=\"font-weight: 400;\">API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture. Here at Cheesecake Labs we do our best to develop APIs following the best practices. We know that it seems time-consuming, but in the long run it pays off!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a software developer, I know how hard it is to contain the urge to start coding as soon as we can. After the first sprint planning, our fingers \u2013 uncontrolled, hungry creatures \u2013 want to start smashing the keyboard, translating our ideas into code fastly and furiously. Despite how great we feel while developing, [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":4152,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[287,319],"class_list":["post-4132","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-product-design","category-opinion","tag-tag-code","tag-tag-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>API Design: Think First, Code Later<\/title>\n<meta name=\"description\" content=\"API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"API Design: Think First, Code Later\" \/>\n<meta property=\"og:description\" content=\"API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\" \/>\n<meta property=\"og:site_name\" content=\"Cheesecake Labs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cheesecakelabs\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-23T17:54:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T17:44:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Cheesecake Labs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cheesecakelabs\" \/>\n<meta name=\"twitter:site\" content=\"@cheesecakelabs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\"},\"author\":{\"name\":\"Jonatas Baldin\"},\"headline\":\"API Design: Think First, Code Later\",\"datePublished\":\"2017-02-23T17:54:09+00:00\",\"dateModified\":\"2022-07-01T17:44:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\"},\"wordCount\":1924,\"commentCount\":4,\"image\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png\",\"keywords\":[\"code\",\"Design\"],\"articleSection\":[\"Product Design\",\"Opinion\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\",\"url\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\",\"name\":\"API Design: Think First, Code Later\",\"isPartOf\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png\",\"datePublished\":\"2017-02-23T17:54:09+00:00\",\"dateModified\":\"2022-07-01T17:44:04+00:00\",\"author\":{\"@type\":\"person\",\"name\":\"Jonatas Baldin\"},\"description\":\"API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture.\",\"breadcrumb\":{\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage\",\"url\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png\",\"contentUrl\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png\",\"width\":2000,\"height\":720,\"caption\":\"API Design\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cheesecakelabs.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API Design: Think First, Code Later\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/#website\",\"url\":\"https:\/\/cheesecakelabs.com\/blog\/\",\"name\":\"Cheesecake Labs\",\"description\":\"Nearshore outsourcing company for Web and Mobile design and engineering services, and staff augmentation for startups and enterprises..\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cheesecakelabs.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"name\":\"Jonatas Baldin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cheesecakelabs.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/jonatas-300x300.jpg\",\"contentUrl\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/jonatas-300x300.jpg\",\"caption\":\"Jonatas Baldin\"},\"description\":\"10 years of experience in Marketing and Sales in the Technology sector. My main purpose is help, support and structure efficient operations and also develop independent and multidisciplinary teams.\",\"url\":\"https:\/\/cheesecakelabs.com\/blog\/autor\/jonatas\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"API Design: Think First, Code Later","description":"API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/","og_locale":"en_US","og_type":"article","og_title":"API Design: Think First, Code Later","og_description":"API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture.","og_url":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/","og_site_name":"Cheesecake Labs","article_publisher":"https:\/\/www.facebook.com\/cheesecakelabs","article_published_time":"2017-02-23T17:54:09+00:00","article_modified_time":"2022-07-01T17:44:04+00:00","og_image":[{"width":2000,"height":720,"url":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png","type":"image\/png"}],"author":"Cheesecake Labs","twitter_card":"summary_large_image","twitter_creator":"@cheesecakelabs","twitter_site":"@cheesecakelabs","twitter_misc":{"Written by":null,"Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#article","isPartOf":{"@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/"},"author":{"name":"Jonatas Baldin"},"headline":"API Design: Think First, Code Later","datePublished":"2017-02-23T17:54:09+00:00","dateModified":"2022-07-01T17:44:04+00:00","mainEntityOfPage":{"@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/"},"wordCount":1924,"commentCount":4,"image":{"@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage"},"thumbnailUrl":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png","keywords":["code","Design"],"articleSection":["Product Design","Opinion"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/","url":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/","name":"API Design: Think First, Code Later","isPartOf":{"@id":"https:\/\/cheesecakelabs.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage"},"image":{"@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage"},"thumbnailUrl":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png","datePublished":"2017-02-23T17:54:09+00:00","dateModified":"2022-07-01T17:44:04+00:00","author":{"@type":"person","name":"Jonatas Baldin"},"description":"API Design matters. It tends to stop people from just hacking things together to take a step back and see the bigger picture.","breadcrumb":{"@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#primaryimage","url":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png","contentUrl":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/02\/Banner_api.png","width":2000,"height":720,"caption":"API Design"},{"@type":"BreadcrumbList","@id":"https:\/\/cheesecakelabs.com\/blog\/api-design-think-first-code-later\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cheesecakelabs.com\/blog\/"},{"@type":"ListItem","position":2,"name":"API Design: Think First, Code Later"}]},{"@type":"WebSite","@id":"https:\/\/cheesecakelabs.com\/blog\/#website","url":"https:\/\/cheesecakelabs.com\/blog\/","name":"Cheesecake Labs","description":"Nearshore outsourcing company for Web and Mobile design and engineering services, and staff augmentation for startups and enterprises..","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cheesecakelabs.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","name":"Jonatas Baldin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cheesecakelabs.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/jonatas-300x300.jpg","contentUrl":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/jonatas-300x300.jpg","caption":"Jonatas Baldin"},"description":"10 years of experience in Marketing and Sales in the Technology sector. My main purpose is help, support and structure efficient operations and also develop independent and multidisciplinary teams.","url":"https:\/\/cheesecakelabs.com\/blog\/autor\/jonatas\/"}]}},"_links":{"self":[{"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/posts\/4132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/comments?post=4132"}],"version-history":[{"count":1,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/posts\/4132\/revisions"}],"predecessor-version":[{"id":10314,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/posts\/4132\/revisions\/10314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/media\/4152"}],"wp:attachment":[{"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/media?parent=4132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/categories?post=4132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheesecakelabs.com\/blog\/wp-json\/wp\/v2\/tags?post=4132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}