<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Golem.ai</title>
    <description>The latest articles on Forem by Golem.ai (@golem-ai).</description>
    <link>https://forem.com/golem-ai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F4171%2F04536fe0-a2d6-4b88-b876-3c24ac7ec821.png</url>
      <title>Forem: Golem.ai</title>
      <link>https://forem.com/golem-ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/golem-ai"/>
    <language>en</language>
    <item>
      <title>HTTP API Lean Workflow: from contract to documentation</title>
      <dc:creator>Ludovic Fleury</dc:creator>
      <pubDate>Fri, 02 Jul 2021 18:04:23 +0000</pubDate>
      <link>https://forem.com/golem-ai/http-api-lean-workflow-from-contract-to-documentation-20m7</link>
      <guid>https://forem.com/golem-ai/http-api-lean-workflow-from-contract-to-documentation-20m7</guid>
      <description>&lt;p&gt;How do we rely on open source software to achieve collaborative API design and produce our &lt;a href="https://developers.golem.ai/docuchecker" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;?&lt;/p&gt;

&lt;h2&gt;
  
  
  TL:DR;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A contract-first approach enables high collaboration and removes overhead.&lt;/li&gt;
&lt;li&gt;Versioning contracts with the code since they share the same lifecycle.&lt;/li&gt;
&lt;li&gt;Stoplight.io DX is a powerful API IDE for OpenAPI.&lt;/li&gt;
&lt;li&gt;Enriching the OpenAPI contract with markdown reduces the cost of maintenance. &lt;/li&gt;
&lt;li&gt;Rely on Redoc to expose the contract as documentation with a standard UX &amp;amp; UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;At &lt;a href="https://golem.ai/" rel="noopener noreferrer"&gt;Golem.ai&lt;/a&gt;, we are maintaining a platform and several services following the &lt;a href="https://en.wikipedia.org/wiki/Service-oriented_architecture" rel="noopener noreferrer"&gt;SOA&lt;/a&gt; concepts. Our protocol between these services relies on &lt;a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm" rel="noopener noreferrer"&gt;REST&lt;/a&gt; API &lt;a href="https://martinfowler.com/articles/richardsonMaturityModel.html#level2" rel="noopener noreferrer"&gt;level 2&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;These API are either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;consumed programmatically (internally and by our customers)&lt;/li&gt;
&lt;li&gt;used by several web applications (addressing both our business analysts and customers)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://openpracticelibrary.com/practice/contract-first-development/" rel="noopener noreferrer"&gt;Contract-first approach&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;There are only two hard things in Computer Science: cache invalidation and naming things.&lt;br&gt;
-- Phil Karlton&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Designing API is a tough job. It's a highly structuring action where we define the boundary of "something". These boundaries exposes our knowledge and understanding about this "something": a service, a micro-service, a bounded context.&lt;/p&gt;

&lt;p&gt;At Golem.ai, API design is not only about decision, responsibility &amp;amp; technicality. We advocate continuous collaboration to guarantee the quality &amp;amp; value of our APIs.&lt;/p&gt;

&lt;p&gt;Adopting the &lt;a href="https://en.wikipedia.org/wiki/Eating_your_own_dog_food" rel="noopener noreferrer"&gt;dogfooding philosophy&lt;/a&gt;, we consume our own API. For every new feature, fix or improvement that impacts an endpoint, we follow this 3-step process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Discovery&lt;/strong&gt;: provider &amp;amp; consumer (example: backend &amp;amp; frontend) engineers sit together and discuss their technical challenges. Exploring code, questioning the &lt;a href="https://basecamp.com/shapeup/webbook" rel="noopener noreferrer"&gt;shape (specification)&lt;/a&gt; and referring to the &lt;a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm" rel="noopener noreferrer"&gt;REST approach&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Agreement&lt;/strong&gt;: ultimately, engineers will come out with a pragmatic and relevant solution. They update with Stoplight.io and version the &lt;a href="https://www.openapis.org/" rel="noopener noreferrer"&gt;OpenAPI contract&lt;/a&gt; with git. Usually, this contract has been drafted during the discovery by both parties.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;: &lt;a href="https://en.wikipedia.org/wiki/Test-driven_development#:~:text=Test%2Ddriven%20development%20(TDD),software%20against%20all%20test%20cases." rel="noopener noreferrer"&gt;TDD&lt;/a&gt; is cheaper, our OpenAPI contracts include examples that provide  a free mock for the client and free test assertion &amp;amp; server-side validation. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Adjustment: nothing is perfect and near perfection takes time and iteration. Developers can adjust an endpoint but they have to go again through steps 1, 2 &amp;amp; 3. Hopefully, adjustments are usually small and the whole process is short, 5 minutes tops: a slack message, a meeting using screen sharing and a quick discussion will lead to a git commit updating the OpenAPI contract.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Contract as Documentation
&lt;/h2&gt;

&lt;p&gt;We needed more than a contract or a reference to on-board, assist, and guide developers using our API. &lt;/p&gt;

&lt;p&gt;Documentation needs maintenance and its lifecycle is tightly bound to the implementation. &lt;/p&gt;

&lt;p&gt;After assessing solutions on the market, we realised that most of the option would either involve changing our workflow or adding complexity to sync the documentation. &lt;/p&gt;

&lt;p&gt;We finally decided to use our OpenAPI contract as documentation with Redoc (read more below). &lt;/p&gt;

&lt;p&gt;The final workflow is simple, involving only the OpenAPI contract, versioned with the code. Our regular pipeline deploy the code and the documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Side effects&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code review validates everything: contract, code &amp;amp; documentation. &lt;/li&gt;
&lt;li&gt;We didn't increase the complexity and the cost of our API.&lt;/li&gt;
&lt;li&gt;Everything, from modelling to documenting, is tied to the lifecycle of the code: ideation, testing, release &amp;amp; deployment. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We ended up maximizing the value of every step of our API management, reducing the overhead for our developers, and removing conflict during integration. &lt;strong&gt;Collaboration versioned in an OpenAPI contract ensure predictable, meaningful, and enjoyable API development.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools: our API Stack
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Stoplight.io
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://stoplight.io/" rel="noopener noreferrer"&gt;Stoplight.io&lt;/a&gt; is a game changing tool when it comes to managing &amp;amp; editing OpenAPI contracts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkfarzd7orpm656bxizl8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkfarzd7orpm656bxizl8.png" alt="Alt Text" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We use the desktop application, so we can locally load our contract from our git repository into the editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next level &lt;a href="https://medium.com/swlh/what-is-dx-developer-experience-401a0e44a9d9" rel="noopener noreferrer"&gt;DX&lt;/a&gt;: none of our developers were familiar with OpenAPI and they didn’t  have to be with stoplight: WYSIWYG for discovery, linter, direct edition in yaml/json, preview... Engineers can focus on the "what" &amp;amp; "why" rather than the "how".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not intrusive: the desktop app lets you define your own convention, standard, directory structure, and workflow. It adapts to your needs and your organization doesn't have to fit the tool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provides a mock server locally. We can even quickly prototype our implementation: our local docker container fetches generated data complying to the defined contract.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Redoc
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/Redocly/redoc" rel="noopener noreferrer"&gt;Redoc&lt;/a&gt; is a fantastic &lt;a href="https://en.wikipedia.org/wiki/Do_it_yourself" rel="noopener noreferrer"&gt;DIY&lt;/a&gt; tool, it leverages the markdown syntax and the OpenAPI description fields to enrich your contract. Basically, &lt;strong&gt;your contract is not only a reference, but becomes your documentation&lt;/strong&gt;, example: &lt;a href="https://developers.golem.ai/docuchecker#section/Getting-started" rel="noopener noreferrer"&gt;this getting started&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As we maintained and documented several services, we needed to aggregate all our contracts/documentations under a single url (developers.golem.ai). This &lt;a href="https://github.com/volbrene/redoc" rel="noopener noreferrer"&gt;Fork&lt;/a&gt; by &lt;a href="https://www.rene-volbach.de/" rel="noopener noreferrer"&gt;Volbrene&lt;/a&gt; solved this problem for us.&lt;/p&gt;

&lt;p&gt;Once again, the &lt;a href="https://stoplight.io/studio/" rel="noopener noreferrer"&gt;stoplight studio desktop app&lt;/a&gt; is bliss, offering markdown edition &amp;amp; preview:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3zpgubtmv29vvqfomf09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3zpgubtmv29vvqfomf09.png" alt="Alt Text" width="800" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Git &amp;amp; Gitlab perk
&lt;/h3&gt;

&lt;p&gt;API contracts are versioned in the same git repository as the related base code at &lt;code&gt;/doc/OpenAPI&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Gitlab offers a &lt;a href="https://docs.gitlab.com/ee/user/project/repository/#openapi-viewer" rel="noopener noreferrer"&gt;nice perk based on a naming convention&lt;/a&gt;. Adding "openapi" in your contract file name enables a swagger-like preview in the gitlab code explorer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmzi9e17zhc7opsauhxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmzi9e17zhc7opsauhxc.png" alt="Alt Text" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Our engineering team is hiring in Paris, France. php/Symfony junior, contact us!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Many thanks to Azure: if you need proofreading contact her at &lt;a href="mailto:heatherklamb@gmail.com"&gt;heatherklamb@gmail.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>rest</category>
      <category>documentation</category>
      <category>openapi</category>
    </item>
  </channel>
</rss>
