<?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>DEV Community: mogui</title>
    <description>The latest articles on DEV Community by mogui (@mogui).</description>
    <link>https://dev.to/mogui</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%2Fuser%2Fprofile_image%2F35825%2F5bcb62be-c35e-4dc0-8a97-d02133505131.jpeg</url>
      <title>DEV Community: mogui</title>
      <link>https://dev.to/mogui</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mogui"/>
    <language>en</language>
    <item>
      <title>Joyce, a highly scalable event-driven Cloud Native Data Hub.</title>
      <dc:creator>mogui</dc:creator>
      <pubDate>Thu, 15 Jul 2021 09:08:02 +0000</pubDate>
      <link>https://dev.to/mogui/joyce-a-highly-scalable-event-driven-cloud-native-data-hub-17f7</link>
      <guid>https://dev.to/mogui/joyce-a-highly-scalable-event-driven-cloud-native-data-hub-17f7</guid>
      <description>&lt;p&gt;Years of blood and struggle, condensed in a few github repositories, finally public with a product emerged from different experiences inside the company I work!&lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;Joyce&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a highly scalable event-driven Cloud Native Data Hub.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ok! Wait, what? &lt;/p&gt;

&lt;p&gt;Joyce allows you to ingest data from (almost) any source and expose the ingested data as standard APIs (REST, event notification) automatically. In order to specify to Joyce which data we want to pick from the incoming data stream and how APIs will look like you need to describe the expected behaviour with a DSL based on json-schema.&lt;/p&gt;

&lt;p&gt;Continue to read about it here : &lt;a href="https://sourcesense.github.io/joyce-docs/"&gt;https://sourcesense.github.io/joyce-docs/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>kubernetes</category>
      <category>kafka</category>
      <category>rest</category>
    </item>
    <item>
      <title>No REST for the wicked</title>
      <dc:creator>mogui</dc:creator>
      <pubDate>Sun, 16 Jul 2017 18:50:20 +0000</pubDate>
      <link>https://dev.to/mogui/no-rest-for-the-wicked-e8l</link>
      <guid>https://dev.to/mogui/no-rest-for-the-wicked-e8l</guid>
      <description>&lt;p&gt;This article (also read as &lt;em&gt;rant&lt;/em&gt;) was heavy inspired by the reading of &lt;a href="https://mmikowski.github.io/the_lie/" rel="noopener noreferrer"&gt;this article&lt;/a&gt;, which puts in words something that was floating in my mind a lot these years of making services talking between each others, being API, mobile client or whatever.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why the fuck are we using &lt;em&gt;REST~ish&lt;/em&gt; API everywhere?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F600%2F0%2AxlUf1WFioivefp16." class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F600%2F0%2AxlUf1WFioivefp16." alt="if you dont get this, we cannot talk about music..."&gt;&lt;/a&gt;if you don’t get this, we cannot talk aboutÂ music…&lt;/p&gt;

&lt;h4&gt;
  
  
  The Problem
&lt;/h4&gt;

&lt;p&gt;It seems that nowadays a decent developer MUST know and use REST, but how we are doing it? &lt;/p&gt;

&lt;p&gt;It’s pretty much clear to me implementing it or just consume it that there’s a lot wrong.  &lt;/p&gt;

&lt;p&gt;Main points are covered by the article cited at the beginning, but I’ll just remark some of them:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. “RESTful APIs are usually tied to HTTP”
&lt;/h4&gt;

&lt;p&gt;and makes use of it scattering logic around too much: headers, verbs, uris, response codes and body. This makes it difficult to debug and totally unintuitive, leading to random implementations.  &lt;/p&gt;

&lt;p&gt;When you want to use a 3rd party RESTxxx API you &lt;strong&gt;have to&lt;/strong&gt; read the documentation because you can’t give anything for granted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do I need to provide an header or a token in the query string to authenticate calls?&lt;/li&gt;
&lt;li&gt;How the header is named?&lt;/li&gt;
&lt;li&gt;To create a resource do I use a POST or a PUT?&lt;/li&gt;
&lt;li&gt;and for an update?&lt;/li&gt;
&lt;li&gt;and for an upsert?&lt;/li&gt;
&lt;li&gt;When an error occurs do I check only the status code or also the payload? (how many apis have the “status” field in the payload? I did it myself too, many times)&lt;/li&gt;
&lt;li&gt;And the error message?&lt;/li&gt;
&lt;li&gt;To filter out or query a list of resource which fields do I use in the query string?&lt;/li&gt;
&lt;li&gt;And if I want something that isn’t a plain resource but a mixed collection?&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. “The REST vocabulary isn’t rich enough”
&lt;/h4&gt;

&lt;p&gt;This is harshly true because REST is designed after the concept of &lt;em&gt;resource&lt;/em&gt;, &lt;em&gt;CRUD&lt;/em&gt; operations and linking them. It is a good model to represent linked data and managing it just like you can do on a RDBMS, but API are usually &lt;strong&gt;not only&lt;/strong&gt; that.  &lt;/p&gt;

&lt;p&gt;Let’s just think of a mobile social app API where within the things you have to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;register a user
-&amp;gt; &lt;em&gt;PUT, POST user resource?&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;authenticate a user
-&amp;gt; &lt;em&gt;is it a resource???&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;create a new blog entry
-&amp;gt; &lt;em&gt;this I know!!&lt;/em&gt; &lt;em&gt;POST /blog yeh!! Done. REST is awesome!&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;like a post
-&amp;gt; &lt;em&gt;mmm could be&lt;/em&gt; &lt;em&gt;POST /blog/666, but I haven’t a payload! Can I use just a GET? and the action does really create a “like” resource or is it just a flag on the blog entry resource? should I use a PUT to update the blog entry resource? … wtf&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;search fora collection of resources
-&amp;gt; &lt;em&gt;GET /resource yes! search criteria and filters? queryString parameters? body payload? if that i need a POST but I am not creating nothing :( fuck wasn’t SOAP better? hell no! but wtf!&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;ask for a profile of a user but with more or few information
-&amp;gt; &lt;em&gt;query string parameter? another uri endpoint?&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;make new friend request
-&amp;gt; &lt;em&gt;ooh fuck!&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F400%2F0%2AHlVw0Hly7m8727AV.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F400%2F0%2AHlVw0Hly7m8727AV.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s a mess and everyone is doing it in a different way, also REST related frameworks roll their own philosophy.&lt;/p&gt;

&lt;p&gt;REST was a bless because it gave us freedom from the strictness of SOAP for example, but at what price?  &lt;/p&gt;

&lt;p&gt;Confusion I guess.&lt;/p&gt;

&lt;p&gt;Whenever we have to design a REST~ish API, we have to answer too much questions and the problem is that &lt;strong&gt;there is no right answer&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Existing solutions
&lt;/h4&gt;

&lt;p&gt;I am obviously not the only one having these feelings so there are people around trying to nail these points, author of the cited article propose his solution &lt;a href="https://mmikowski.github.io/json-pure/" rel="noopener noreferrer"&gt;JSON-pure API&lt;/a&gt;. I think that it’s not so beautiful and usable, it kind feel going back to a SOAP~ish thing, but it has great ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;be agnostic of the transport, no more significant content attached to protocol specific things, like response code and headers, enable the use of whatever transport we should need: HTTP, Websocket, XMPP …&lt;/li&gt;
&lt;li&gt;JSON is easy to debug&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More stable and adopted things are out there: &lt;a href="http://jsonapi.org/" rel="noopener noreferrer"&gt;jsonapi&lt;/a&gt;, &lt;a href="http://stateless.co/hal_specification.html" rel="noopener noreferrer"&gt;HAL&lt;/a&gt;, &lt;a href="https://github.com/JornWildt/Mason" rel="noopener noreferrer"&gt;Mason&lt;/a&gt;, &lt;a href="https://github.com/collection-json/spec" rel="noopener noreferrer"&gt;Collection json&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
 I think that each one either is not complete or just addresses the same resource/CRUD model, just in a different way.&lt;/p&gt;

&lt;p&gt;What also I think is: we need a sort of &lt;em&gt;standard&lt;/em&gt; to do &lt;em&gt;standard things&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
 I think that there should be a best practice to do authentication for API, error handling and response format, things that from an API consumer point of view let you integrate more quickly.  &lt;/p&gt;

&lt;p&gt;SOAP, bad as it was, let you create clients by themselves that maybe it is too much, but it was intuitive to use, REST~ish things are not.  &lt;/p&gt;

&lt;p&gt;No, I don’t want to go back to SOAP :P so…&lt;/p&gt;
&lt;h4&gt;
  
  
  An idea…
&lt;/h4&gt;

&lt;p&gt;The new idea is an old idea.  &lt;/p&gt;

&lt;p&gt;I don’t mean to write a new protocol specification.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F500%2F0%2AA-KwNlmdkUdMlKfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F500%2F0%2AA-KwNlmdkUdMlKfo.png" alt="xkcd"&gt;&lt;/a&gt;xkcd&lt;/p&gt;

&lt;p&gt;I think that the right things are already there but have just to be put together.  &lt;/p&gt;

&lt;p&gt;So what I want to write is more a “Specification of best practice” or a “Protocol that is just already-known-protocols composition”.&lt;/p&gt;
&lt;h4&gt;
  
  
  What it should be made of?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Since API are not just CRUD operation but more something like &lt;em&gt;actions&lt;/em&gt; or &lt;em&gt;procedure&lt;/em&gt; maybe a simple &lt;strong&gt;RPC&lt;/strong&gt; is what we need. We already have a nice specification: &lt;a href="http://www.jsonrpc.org/specification" rel="noopener noreferrer"&gt;JSON-RPC&lt;/a&gt;. It’s clean, simple as json, agnostic from the transport and there’s already a lot of clients libraries.&lt;/li&gt;
&lt;li&gt;Requests authentication, where needed, should be embedded in this protocol and &lt;a href="https://jwt.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;JWT&lt;/strong&gt;&lt;/a&gt; I thinks is the right fit for that.
Also RPC methods regarding authentication should be in the protocol specification standardising the jwt generation.&lt;/li&gt;
&lt;li&gt;We can make a hazardous jump and have &lt;a href="http://json-schema.org" rel="noopener noreferrer"&gt;JSON Schema&lt;/a&gt; over the JSON-RPC payload to validate the API format, and with little effort have the API clients library autogenerated from the schema (hello again SOAP :3 ).&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Are you sure you need RPC there’s this thing called GraphQL …
&lt;/h4&gt;

&lt;p&gt;It’s been a while since I jot down these thoughts about REST, but never wrapped in an organic discussion, it seems I waited too long. It’s not yesterday that I have stumbled upon &lt;a href="//graphql.org"&gt;GraphQL&lt;/a&gt;, knowing it just superficially, I have seen it just as a wonderful way to retrieve data. A closer look made me totally reconsider RPC. With &lt;em&gt;Mutations&lt;/em&gt; you can achieve anything, it is really just like an RPC declaring ahead what you want as a result, beautiful. What you miss from RPC is a uniformed error handling in the response, GraphQL doesn’t enforce anything in this regard. What doesn’t change from RPC is that GraphQL doesn’t deal with authentication too, so you have to take care of that by yourself, who said JWT??.&lt;br&gt;&lt;br&gt;
 We can embed both in query/mutation, something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mutation {
  login(username: String!, password: String!) {
    token
    error
  }
}

query {
    myUltraAwesomeApi(token: String, aParameter: String) {
        error,
        result
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusions
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;It’s time to put REST at rest&lt;/em&gt;, and make API by combine these old/new technologies that are really more appropriate in a many cases. So go out and play with &lt;strong&gt;RPC&lt;/strong&gt; , &lt;strong&gt;GraphQL&lt;/strong&gt; and  &lt;strong&gt;JWT&lt;/strong&gt;!&lt;/p&gt;




</description>
      <category>json</category>
      <category>graphql</category>
      <category>api</category>
      <category>jwt</category>
    </item>
  </channel>
</rss>
