<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ravi Teja Gudapati on Medium]]></title>
        <description><![CDATA[Stories by Ravi Teja Gudapati on Medium]]></description>
        <link>https://medium.com/@tejainece?source=rss-870a21a0e195------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*icvY-5GM6bjGk7h0.</url>
            <title>Stories by Ravi Teja Gudapati on Medium</title>
            <link>https://medium.com/@tejainece?source=rss-870a21a0e195------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:14:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tejainece/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding size of terminal in Dart]]></title>
            <link>https://medium.com/@tejainece/finding-size-of-terminal-in-dart-5f72e95215b8?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f72e95215b8</guid>
            <category><![CDATA[width]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[size]]></category>
            <category><![CDATA[height]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sun, 17 Dec 2017 20:44:19 GMT</pubDate>
            <atom:updated>2017-12-17T20:44:19.803Z</atom:updated>
            <content:encoded><![CDATA[<p>Dart makes it very easy to find the runtime size of the terminal window.</p><p><a href="https://api.dartlang.org/stable/dart-io/Stdout/terminalLines.html"><strong>terminalLines</strong></a> and <a href="https://api.dartlang.org/stable/dart-io/Stdout/terminalColumns.html"><strong>terminalColumns</strong></a> fields on an instance of <a href="https://api.dartlang.org/stable/dart-io/Stdout-class.html"><strong>Stdout</strong></a> object provides the number of lines and columns respectively of the terminal attached to it.</p><p>Here is a small example that listens for the change in terminal size and prints the new size:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7dfa81be2ee22cd0ddcc75e80ad836b/href">https://medium.com/media/d7dfa81be2ee22cd0ddcc75e80ad836b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f72e95215b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mongo backed REST apis with Jaguar: A simple introduction]]></title>
            <link>https://medium.com/@tejainece/mongo-backed-rest-apis-with-jaguar-a-simple-introduction-3b1c1240d51e?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b1c1240d51e</guid>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[rest]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sat, 04 Nov 2017 09:29:01 GMT</pubDate>
            <atom:updated>2017-11-06T13:41:13.826Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post, we will develop a tiny tiny server to demonstrate using Mongo DB with Jaguar. The server’s purpose is to manage ‘Todo list’.</p><h3>Skeleton of the Api</h3><p>It exposes two routes.</p><ol><li>One route to get existing Todo items</li><li>One route to post a new Todo item</li></ol><pre>@Api(path: &#39;/api/todo&#39;)<br>class TodoApi {<br><br>  @Get()<em><br>  </em>Future&lt;String&gt; fetchAll(Context ctx) async {<br>    <em>// TODO something here ...</em><br>  }<br><br>  @Post()<br>  Future&lt;String&gt; add(Context ctx) async {<br>    // TODO something here<br>  }<br>}</pre><h3>Connection to Mongo DB</h3><p>Make sure your Mongo DB server is running.</p><pre>sudo service mongod start</pre><p><a href="https://www.dartdocs.org/documentation/jaguar_mongo/latest/jaguar_mongo/MongoDb-class.html">MongoDb</a> interceptor shall be wrapped around routes to automatically connect and release connection to Mongo DB server every request. We assume that the Mongo DB server runs at the address localhost:27018 .</p><pre><em>@Api(path: &#39;/api&#39;)<br>class TodoApi {<br>  // Declare Mongo interceptor<br>  </em><strong><em>MongoDb mongoDb(Context ctx) =&gt; new MongoDb(&#39;mongodb://localhost:27018/test&#39;);</em></strong><em><br><br>  @Get()<br>  </em><strong><em>@WrapOne(</em>#mongoDb<em>)</em></strong><em>  // Wrap the mongo interceptor around a route<br>  Future&lt;String&gt; fetchAll(Context ctx) </em>async<em> {<br>    // ...<br>  }</em><br><br>  @Post()<br>  <strong><em>@WrapOne(</em>#mongoDb<em>)</em></strong><em>  // Wrap the mongo interceptor around a route</em>     <br>  Future&lt;String&gt; add(Context ctx) async {<br>    // TODO something here<br>  }<em><br>}</em></pre><p><a href="https://www.dartdocs.org/documentation/jaguar_mongo/latest/jaguar_mongo/MongoDb-class.html">MongoDb</a> interceptor injects the per-request Db connection into the interceptor inputs of <a href="https://www.dartdocs.org/documentation/jaguar/latest/jaguar/Context-class.html">Context</a> . This can be obtained using <a href="https://www.dartdocs.org/documentation/jaguar/latest/jaguar/Context/getInput.html">getInput</a> method of <a href="https://www.dartdocs.org/documentation/jaguar/latest/jaguar/Context-class.html">Context</a> .</p><pre><em>@Get()<br></em><strong><em>@WrapOne(</em>#mongoDb<em>)</em></strong><em>  // Wrap the mongo interceptor around a route<br>Future&lt;String&gt; fetchAll(Context ctx) </em>async<em> {<br>  // Get the Db instance from the interceptor<br>  </em><strong><em>final Db db = ctx.getInput(MongoDb);</em></strong><em><br>  // Use Db to fetch Todo items<br>  final res = </em>await<em> (</em>await<em> db.collection(&#39;todo&#39;).find()).toList();<br>  return </em>await<em> JSON.encode(res);<br>}</em></pre><p>Tada! You have successfully connected and fetched information from Mongo DB database.</p><h3>Full server code</h3><pre>import &#39;dart:async&#39;;<br>import &#39;dart:convert&#39;;<br>import &#39;package:jaguar/jaguar.dart&#39;;<br>import &#39;package:mongo_dart/mongo_dart.dart&#39;;<br>import &#39;package:jaguar_mongo/jaguar_mongo.dart&#39;;</pre><pre>@Api(path: &#39;/api/todo&#39;)<br>class TodoApi {<br>  <em>// Mongo interceptor<br>  </em>MongoDb mongoDb(Context ctx) =&gt; new MongoDb(&#39;mongodb://localhost:27018/test&#39;);<br><br>  @Get()<br>  @WrapOne(#mongoDb) <em>// Wrap the mongo interceptor around a route<br>  </em>Future&lt;String&gt; fetchAll(Context ctx) async {<br>    <em>// Get the Db instance from the interceptor<br>    </em>final Db db = ctx.getInput(MongoDb);<br>    <em>// Use Db to fetch Todo items<br>    </em>final res = await (await db.collection(&#39;todo&#39;).find()).toList();<br>    return await JSON.encode(res);<br>  }<br><br>  @Post()<br>  @WrapOne(#mongoDb)<br>  Future&lt;String&gt; add(Context ctx) async {<br>    final Map body = await ctx.req.bodyAsJsonMap();<br>    final Db db = ctx.getInput(MongoDb);<br>    await db.collection(&#39;todo&#39;).insert(body);<br>    <em>// Use Db to fetch Todo items<br>    </em>final res = await (await db.collection(&#39;todo&#39;).find()).toList();<br>    return await JSON.encode(res);<br>  }<br>}</pre><pre>Future server() async {<br>  final jaguar = new Jaguar();<br>  jaguar.addApiReflected(new TodoApi());<br><br>  await jaguar.serve();<br>}</pre><h3><strong>Client code</strong></h3><pre>import &#39;package:http/http.dart&#39;;<br>import &#39;package:jaguar_client/jaguar_client.dart&#39;;</pre><pre>final client = new Client();</pre><pre>Future doClient() async {<br>  final url = &#39;http://localhost:8080/api/todo&#39;;<br>  final jClient = new JsonClient(client);<br><br>  final res = (await jClient.get(url)).deserialize();<br>  print(res);<br>  print((await jClient.post(url, body: {&#39;text&#39;: &#39;Laundry&#39;, &#39;time&#39;: &#39;Today&#39;}))<br>      .deserialize());<br>  print((await jClient.get(url)).deserialize());<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b1c1240d51e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jaguar Dart: Serving static files]]></title>
            <link>https://medium.com/@tejainece/jaguar-dart-serving-static-files-6452e922bfac?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/6452e922bfac</guid>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[static-file]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sun, 15 Oct 2017 19:00:51 GMT</pubDate>
            <atom:updated>2017-12-26T10:18:42.522Z</atom:updated>
            <content:encoded><![CDATA[<p>Serving static files is a common task in server-side programming. A good server-side framework should provide an easy and intuitive way to serve static files. Jaguar does this elegantly out-of-the-box through <a href="https://www.dartdocs.org/documentation/jaguar/latest/jaguar/Jaguar/staticFiles.html">staticFiles</a> method.</p><h3>Example</h3><p>Lets see the sample code before we delve into details:</p><pre>main(List&lt;String&gt; arguments) <strong>async </strong>{<br>  <strong>final </strong>server = <strong>new </strong>Jaguar();<br><br>  <em>// Serve with prefix stripped. Similar to &#39;alias&#39; in Nginx.<br>  </em>server.staticFiles(<strong>&#39;/static/*&#39;</strong>, <strong>&#39;static&#39;</strong>); // The magic!<br><br>  <strong>await </strong>server.serve();<br>}</pre><p>That one line is all you need to serve content under the directory static with request path /static/*.</p><p>The second argument directory specifies the disk or virtual directory from which static file contents are retrieved.</p><p>The first argument path is the HTTP request path that must match for the static content to be served. This follows the same rules as <a href="https://medium.com/@tejainece/route-paths-and-path-variables-in-jaguar-dart-344525b94542">any other route path</a>.</p><p>The named argument stripPrefix determines if the matched portion of the request shall be discarded while looking up the file in directory or not.</p><p>For example,</p><p>With path /static/* , the request path to directory path mapping is as follows:</p><ol><li>/static/index.html -&gt; directory.path + index.html</li><li>/static/one/index.html -&gt; directory.path + one/index.html</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6452e922bfac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One-to-One ORM relations in Dart]]></title>
            <link>https://medium.com/@tejainece/one-to-one-orm-relations-in-dart-bef284e6001a?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/bef284e6001a</guid>
            <category><![CDATA[has-one]]></category>
            <category><![CDATA[one-to-one]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[dartlang]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sun, 24 Sep 2017 21:12:43 GMT</pubDate>
            <atom:updated>2017-09-25T07:35:48.994Z</atom:updated>
            <content:encoded><![CDATA[<p>One-to-one relationship links one row in a table to one (and only one) row in another table. For example, a User has one Address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*QFgb6X8lX6wff6is4s6c1Q.png" /><figcaption>Tables schema diagram</figcaption></figure><h3><strong>Models</strong></h3><pre><strong>class </strong>User {<br>  @PrimaryKey(length: 50)<br>  String <strong>id</strong>;<br><br>  @Column(length: 50)<br>  String <strong>name</strong>;<br><br>  @HasOne(AddressBean)<br>  Address <strong>address</strong>;<br><br>  <strong>static const </strong>String <em>tableName </em>= <strong>&#39;_user&#39;</strong>;<br><br>  String toString() =&gt; <strong>&quot;User(</strong>$<strong>id, </strong>$<strong>name, </strong>$<strong>address)&quot;</strong>;<br>}<br><br><strong>class </strong>Address {<br>  @PrimaryKey(length: 50)<br>  String <strong>id</strong>;<br><br>  @Column(length: 150)<br>  String <strong>street</strong>;<br><br>  @BelongsTo(UserBean)<br>  String <strong>userId</strong>;<br><br>  <strong>static </strong>String <em>tableName </em>= <strong>&#39;address&#39;</strong>;<br><br>  String toString() =&gt; <strong>&quot;Address(</strong>$<strong>id, </strong>$<strong>userId, </strong>$<strong>street)&quot;</strong>;<br>}<br><br>@GenBean()<br><strong>class </strong>UserBean <strong>extends </strong>Bean&lt;User&gt; <strong>with </strong>_UserBean {<br>  UserBean(Adapter adapter)<br>      : <strong>addressBean </strong>= <strong>new </strong>AddressBean(adapter),<br>        <strong>super</strong>(adapter);<br><br>  <strong>final </strong>AddressBean <strong>addressBean</strong>;<br>}<br><br>@GenBean()<br><strong>class </strong>AddressBean <strong>extends </strong>Bean&lt;Address&gt; <strong>with </strong>_AddressBean {<br>  AddressBean(Adapter adapter) : <strong>super</strong>(adapter);<br>}</pre><p>Running <strong>orm</strong> CLI should generates _UserBean and _AddressBean.</p><h4>Defining forward relationship</h4><p>HasOne annotation defines a forward relationship. It declares that User has one Address.</p><p>HasOne annotation takes the bean for child model (AddressBean, in this case). It uses the BelongsTo declarations on child model (Address) to establish association between the two tables.</p><p><strong>Note</strong>: UserBean must have a field named addressBean of type AddressBean.</p><h4>Defining reverse relationship</h4><p>Reverse relationship links child model to the parent model. This is done using foreign keys declared by the annotation BelongsTo. It takes the bean of parent model (UserBean, in this case) as argument. This links field userId in Address model with id in User model.</p><h3><strong>The magic</strong></h3><p><strong>jaguar_orm_cli</strong> generates all the ORM methods from the specification above in _UserBean and _AddressBean classes.</p><h3>One-to-One cascaded insert</h3><pre><strong>final </strong>user = <strong>new </strong>User()<br>  ..<strong>id </strong>= <strong>&#39;1&#39;<br>  </strong>..<strong>name </strong>= <strong>&#39;Teja&#39;<br>  </strong>..<strong>address </strong>= (<strong>new </strong>Address()<br>    ..<strong>id </strong>= <strong>&#39;1&#39;<br>    </strong>..<strong>street </strong>= <strong>&#39;Stockholm&#39;</strong>);<br><strong>await </strong>userBean.insert(user, cascade: <strong>true</strong>);</pre><p>The above code inserts a User and also associates and inserts the child Address .</p><h3>One-To-One preloaded read</h3><pre><strong>final </strong>user = <strong>await </strong>userBean.find(<strong>&#39;1&#39;</strong>, preload: <strong>true</strong>);<br>print(user);</pre><p>This should print:</p><blockquote>User(1, Teja, Address(1, 1, Stockholm))</blockquote><p>Watch how the child is automatically fetched!</p><h3>One-To-One cascaded update</h3><pre>User user = <strong>await </strong>userBean.find(<strong>&#39;1&#39;</strong>, preload: <strong>true</strong>);<br>user.<strong>name </strong>= <strong>&#39;Teja Hackborn&#39;</strong>;<br>user.<strong>address</strong>.<strong>street </strong>= <strong>&#39;Stockholm, Sweden&#39;</strong>;<br><strong>await </strong>userBean.update(user, cascade: <strong>true</strong>);</pre><p>Lets read it and print it out:</p><pre><strong>final </strong>user = <strong>await </strong>userBean.find(<strong>&#39;1&#39;</strong>, preload: <strong>true</strong>);<br>print(user);</pre><p>Print out:</p><blockquote>User(1, Teja Hackborn, Address(1, 1, Stockholm, Sweden))</blockquote><p>Watch how both the parent and child have been updated!</p><h3>One-To-One cascaded delete</h3><pre><strong>await </strong>userBean.remove(<strong>&#39;1&#39;</strong>, <strong>true</strong>);</pre><p>Lets read it and print it out:</p><pre><strong>final </strong>users = <strong>await </strong>userBean.getAll();<br>print(users);<br><strong>final </strong>addresses = <strong>await </strong>addressBean.getAll();<br>print(addresses);</pre><p>Print out:</p><blockquote>[User(2, Kleak, null)]<br>[Address(2, 2, Stockholm)]</blockquote><p>Watch how both the parent and its child have been deleted!</p><h3>Remove children belonging to parent</h3><pre><strong>await </strong>addressBean.removeByUser(<strong>&#39;2&#39;</strong>);</pre><h3>Preload multiple parent instances</h3><pre><strong>final </strong>users = <strong>await </strong>userBean.getAll();<br><strong>await </strong>userBean.preloadAll(users);</pre><h3>Associate a child to its parent</h3><pre>user = <strong>await </strong>userBean.find(<strong>&#39;2&#39;</strong>);<br><strong>final </strong>address = <strong>new </strong>Address()<br>  ..<strong>id </strong>= <strong>&#39;2&#39;<br>  </strong>..<strong>street </strong>= <strong>&#39;Stockholm&#39;</strong>;<br>addressBean.associateUser(address, user);<br><strong>await </strong>addressBean.insert(address);</pre><p>In our next post, we will demistify One-To-Many relations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bef284e6001a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling CORS requests in Dart server]]></title>
            <link>https://medium.com/@tejainece/handling-cors-requests-in-dart-server-f3eaedb0cdd6?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3eaedb0cdd6</guid>
            <category><![CDATA[ajax]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[cross-domain]]></category>
            <category><![CDATA[cors]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Mon, 18 Sep 2017 19:33:51 GMT</pubDate>
            <atom:updated>2017-09-25T07:34:35.926Z</atom:updated>
            <content:encoded><![CDATA[<p>Cross Origin Resource Sharing (CORS) allows clients on one domain to access resources/routes on a different foreign domain.</p><h3>The foreign server</h3><p>Let us consider a foreign server with following route running on <strong><em>foreign.com</em></strong> domain.</p><pre>@Api(path: <strong>&#39;/api&#39;</strong>)<br><strong>class </strong>Routes {<br>  @Get()<br>  Response&lt;String&gt; get(Context ctx) {<br>    <strong>return </strong>Response.<em>json</em>(<strong>&#39;Hello foreigner!&#39;</strong>);<br>  }<br>}<br><br>main() <strong>async </strong>{<br>  <strong>final </strong>server = <strong>new </strong>Jaguar(port: 9000);<br>  server.addApiReflected(<strong>new </strong>Routes());<br>  server.<strong>log</strong>.<strong>onRecord</strong>.listen(print);<br>  <strong>await </strong>server.serve();<br>}</pre><h3>The client</h3><p>Lets consider the client running on <strong>mine.com</strong> domain.</p><pre><strong>final resp = await </strong>jClient.get(<strong>&#39;http://foreign.com/api/&#39;</strong>);</pre><h3>The problem</h3><p>As expected, chrome (and all other browsers) would throw an error on this request because the route belongs to a different domain.</p><h3>The solution</h3><p>To fix this problem, routes on <strong>foreign.com</strong> domain must accept cross-domain requests from <strong>mine.com</strong>.</p><p>A CORS request involves an initial preflight request with OPTIONS method. This is the request automatically sent by the browser to test if the foreign domain allow CORS for current domain.</p><p>Only when the preflight request succeeds, does the browser proceeds to place the actual request requested by the client.</p><h3>CORS-ifying foreign.com</h3><p>Adding CORS to routes in Jaguar server is very simple. <strong>jaguar_cors</strong> package provides <strong>Cors</strong> interceptor. This interceptor can be wrapped around around routes that need CORS capabilities.</p><p>The interceptor can be configured using <strong>CorsOption</strong> object which it accepts as the only parameter to its constructor.</p><pre><strong>abstract class </strong>CorsHelper {<br>  <strong>static const </strong><em>options1 </em>= <strong>const </strong>CorsOptions(<br>      <em>// Allow CORS requests from mine.com<br>      </em>allowedOrigins: <strong>const </strong>[<strong>&#39;http://mine.com&#39;</strong>],<br>      <em>// Allow all headers<br>      </em>allowAllHeaders: <strong>true</strong>,<br>      <em>// Allow all methods<br>      </em>allowAllMethods: <strong>true</strong>);<br><br>  Cors cors(Context ctx) =&gt; <strong>new </strong>Cors(<em>options1</em>);<br>}<br><br>@Api(path: <strong>&#39;/api&#39;</strong>)<br><strong>class </strong>Routes <strong>extends </strong>Object <strong>with </strong>CorsHelper {<br>  @Route(methods: <strong>const </strong>[<strong>&#39;GET&#39;</strong>, <strong>&#39;OPTIONS&#39;</strong>])<br>  @WrapOne(<strong>#cors</strong>)<br>  Response&lt;String&gt; get(Context ctx) {<br>    <strong>if </strong>(ctx.<strong>req</strong>.<strong>method </strong>!= <strong>&#39;GET&#39;</strong>) <strong>return null</strong>; // Skip during preflight<br>    <strong>return </strong>Response.<em>json</em>(<strong>&#39;Hello foreigner!&#39;</strong>);<br>  }<br>}</pre><p>Notice how OPTIONS method must be allowed on target route. Also notice how the body of the route is skipped for preflight request.</p><h3>Configuration</h3><p>These are the list of options supported by <strong>CorsOption.</strong></p><ul><li>allowedOrigins List&lt;String&gt;: A list of origins a cross-domain request can be executed from. Setting <em>allowAllOrigins</em> to <em>true</em> overrides <em>allowedOrigins</em> and allows all origins.</li><li>allowAllOrigins bool: Allows all origins. If set to <em>true</em>, overrides <em>allowedOrigins</em> option.</li><li>allowedMethods List&lt;String&gt;: A list of methods the client is allowed to use with cross-domain requests. Default value is simple methods (GET and POST).</li><li>allowAllMethods bool: Allows all methods. If set to <em>true</em>, overrides <em>allowedMethods</em> option.</li><li>allowedHeaders List&lt;String&gt;: A list of non simple headers the client is allowed to use with cross-domain requests.</li><li>allowAllHeaders bool: Allows all headers. If set to <em>true</em>, overrides <em>allowedHeaders</em> option.</li><li>exposeHeaders List&lt;String&gt;: Indicates which headers are safe to expose to the API of a CORS API specification</li><li>exposeAllHeaders bool: Exposes all headers. If set to <em>true</em>, overrides <em>exposeHeaders</em> option.</li><li>allowCredentials bool: Indicates whether the request can include user credentials like cookies, HTTP authentication or client side SSL certificates. The default is <em>false</em>.</li><li>maxAge int: Indicates how long (in seconds) the results of a preflight request can be cached. The default is 0 which stands for no max age.</li><li>vary bool:</li><li>allowNonCorsRequests bool: Should non-CORS requests be allowed?</li></ul><p>See <a href="https://www.dartdocs.org/documentation/jaguar_cors/latest/jaguar_cors/CorsOptions-class.html">API documentation</a> for more info.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3eaedb0cdd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload files with Jaguar.dart (using HTML form)]]></title>
            <link>https://medium.com/@tejainece/upload-files-with-jaguar-dart-using-html-form-d98dc5d2e894?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/d98dc5d2e894</guid>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[dataform]]></category>
            <category><![CDATA[upload]]></category>
            <category><![CDATA[multipart]]></category>
            <category><![CDATA[dartlang]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Fri, 09 Jun 2017 21:34:37 GMT</pubDate>
            <atom:updated>2018-07-15T20:10:33.029Z</atom:updated>
            <content:encoded><![CDATA[<h3>The client</h3><p>Files can be uploaded from the browser to the server using multiform/form-data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f3e7b834b10270fd35cf46fbd5236d9/href">https://medium.com/media/0f3e7b834b10270fd35cf46fbd5236d9/href</a></iframe><p>No special Dart or Javascript code is required on browser-side. HTML forms can automatically encode forms as multipart/form-data when the attribute enctype is set to multipart/form-data.</p><h3>The server</h3><p>Jaguar has built-in support to decode multipart/form-data body from http request. bodyAsFormData method on Context object returns decoded form-data in the form of Map&lt;String, FormField&gt;.</p><p>Map&lt;String, FormField&gt; formData = await ctx.req.bodyAsFormData();</p><p>Fields of form-data can be accessed using Map subscript operator.</p><p>BinaryFileFormField pic = formData[&#39;pic&#39;];</p><p>The content of the file can be obtained as Stream&lt;List&lt;int&gt;&gt; using the value member.</p><p>Stream&lt;List&lt;int&gt;&gt; fileData = pic.value;</p><p>Use writeTo method to write to a file directly.</p><p>await pic.writeTo(&#39;media/&#39; + pic.filename);</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd8b377596459f55c7f500b68aab6187/href">https://medium.com/media/fd8b377596459f55c7f500b68aab6187/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d98dc5d2e894" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Instant REST-ification of CRUD operations on Mongo collections]]></title>
            <link>https://medium.com/@tejainece/instant-rest-ification-of-curd-operations-on-mongo-collections-4256f4d49806?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/4256f4d49806</guid>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sat, 04 Mar 2017 22:01:57 GMT</pubDate>
            <atom:updated>2017-09-18T19:37:08.920Z</atom:updated>
            <content:encoded><![CDATA[<p>Jaguar data store is a database neutral abstraction of CRUD operations over table/collection/record. Jaguar Resource uses the data stores to expose the table/collection/record as REST API with little to no effort from the programmer. Jaguar data store also provides client to easily interact with data stores.</p><p>MongoDB data stores reside in the package jaguar_mongo_data_store . <a href="https://www.dartdocs.org/documentation/jaguar_mongo_data_store/0.0.5/resource/MongoResource/MongoResource.html">MongoResource</a> accepts the following argument to expose the collection as REST API:</p><ul><li>mongoUrl : URL to MongoDB database</li><li>collectionName : Name of the collection to be exposed</li><li>jsonSerializer : Serializer to convert a model to and from JSON</li><li>mongoSerializer : Serializer to convert a model to and from Mongo</li></ul><h3>The model</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12985b4cc09a9278f9bc20005a902a56/href">https://medium.com/media/12985b4cc09a9278f9bc20005a902a56/href</a></iframe><h3>The serializers</h3><p>We need a serializer for mongo and a serializer for JSON. jaguar_serializer and jaguar_serializer_mongo packages are used to generate serializers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7c307effc77752f9cd2821aea57e770/href">https://medium.com/media/c7c307effc77752f9cd2821aea57e770/href</a></iframe><h3>The API</h3><p>Now lets add the MongoResource&lt;Post&gt; into our API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f302768bd19fc7225541564a83845067/href">https://medium.com/media/f302768bd19fc7225541564a83845067/href</a></iframe><h3>The client</h3><p><a href="https://www.dartdocs.org/documentation/jaguar_data_store/0.0.11/client/ResourceClient-class.html">ResourceClient</a> can be used to easily access CRUD REST API exposed using data stores.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e1513893b8c5d5e90363373cfd28867/href">https://medium.com/media/4e1513893b8c5d5e90363373cfd28867/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4256f4d49806" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using MongoDB with Jaguar.dart]]></title>
            <link>https://medium.com/@tejainece/using-mongodb-with-jaguar-dart-8ca5f7c8e671?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ca5f7c8e671</guid>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[orm]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sat, 04 Mar 2017 20:25:53 GMT</pubDate>
            <atom:updated>2017-09-18T19:37:43.596Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will cover mongo interceptor, serialization and doing CRUD operations on mongo.</p><h4>Packages used</h4><p>mongo-dart : MongoDB client for Dart.</p><p>jaguar_mongo : mongo interceptor for Jaguar.</p><p>jaguar_serializer_mongo :jaguar_serializer based serializer for mongo.</p><h3>Manually establishing a connection</h3><p>A connection can be established with MongoDB manually using open method of Db object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30153d3dc4af90bf768021db52a0b647/href">https://medium.com/media/30153d3dc4af90bf768021db52a0b647/href</a></iframe><p>This has some disadvantages though:</p><ol><li>It doesn’t use connection pools.</li><li>You have to manually make sure the connection is released when there is an exception in the route handling.</li><li>Other interceptors and route handlers cannot share the same connection.</li></ol><p>If you still decide to establish connection manually, skip the <em>Interceptor</em> section of the blog post and move directly to <em>Serialization</em> section.</p><h3>Interceptor</h3><p>MongoDb interceptor available in jaguar_mongo package performs the following:</p><ol><li>Establishes connection to MongoDB on route entry</li><li>Uses connection pool to <br>- Limit number of simultaneously open connections<br>- Reuse open connections</li><li>Releases connection to connection pool on route exit</li><li>Releases connection to connection pool when there is an exception in route processing</li></ol><h4>Connection pool</h4><p>MongoDb interceptor internally uses connection pool to</p><ol><li>Limit number of simultaneously open connections</li><li>Reuse open connections</li></ol><p>This enhances the performance and requests per second metric of the server.</p><h4>Connection release on exit and exception</h4><p>MongoDb interceptor also makes sure that the connection is released back to the connection pool on route exit and more importantly also when an exception occurs on route processing.</p><h3>Serialization</h3><p>Before we look at how to do CRUD operations on MongoDB, we must figure out a way to serialize our model objects to and from Map, which mongo-dart api expects.</p><p>This can be done manually by writing toMongo and fromMongo methods on model classes. Care must be taken to convert mongo ObjectId to String .</p><p>Or any of the many serialization libraries available on pub repository can be used to serialize Dart object to mongo Map . In this post, we will usejaguar_serializer.</p><h4>Defining the model</h4><p>Lets define the TodoItem model we will use through out this blog post.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac2aa2a01f5c8fc81a81f4e1bddc65ae/href">https://medium.com/media/ac2aa2a01f5c8fc81a81f4e1bddc65ae/href</a></iframe><h4>Defining Mongo serializer for TodoItem</h4><p>Next step is to define the mongo serializer for TodoItem using jaguar_serializer and jaguar_serializer_mongo .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2822d6e93c16fd4e07c6bb6f7ad4411a/href">https://medium.com/media/2822d6e93c16fd4e07c6bb6f7ad4411a/href</a></iframe><p>All serializes must extend from Serializer class. The model that this serializer will be serializing is specified as the template argument ( TodoItem in this case).</p><p>You should notice immediately that Dart analyzer complains that TodoItemMongoSerializer has missing implementation of methods toMap and fromMap . You can either manually write it or let jaguar_serializer generator generate them for you.</p><p>@GenSerializer() informs jaguar_serializer generator that it needs to generate_$TodoItemMongoSerializer containing toMap and fromMap serialization methods for TodoItem model.</p><p>@MongoId annotation informs jaguar_serializer generator to convert id field between String and mgo’s ObjectId during serialization. @EnDecodeField annotation requests the property id to be serialized as _id as required by MongoDB.</p><h4>Generating the _$TodoItemMongoSerializer</h4><p>Installing Jaguar cli generator:</p><blockquote>pub global activate jaguar_cli</blockquote><p>Check that the above command was successful by typing the following in the terminal:</p><blockquote>jaguar help</blockquote><p>Add following clause to jaguar.yaml in project root directory:</p><blockquote><strong>serializers:<br> </strong>- lib/api.dart</blockquote><p><strong>Note</strong>: Assumes your serializer is in api.dart file.</p><p>Its time to build!</p><blockquote>jaguar build</blockquote><p>Generator should have generated api.g.dart if there were no errors. Part this file in api.dart .</p><blockquote>part ‘api.g.dart’</blockquote><p>Lets test our newly generated serializer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c87fa33329d29c09eae8d38a99c2e150/href">https://medium.com/media/c87fa33329d29c09eae8d38a99c2e150/href</a></iframe><p>This should print:</p><blockquote>{_id: ObjectId(“111111111111111111111111”), title: Item 1, message: Message 1}</blockquote><h4>JSON serializer for TodoItem</h4><p>We need a serializer to convert out TodoItem model to JSON for the browser/mobile/desktop client.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e88ed40a6e4c859cfae23c6b2d1e4e0c/href">https://medium.com/media/e88ed40a6e4c859cfae23c6b2d1e4e0c/href</a></iframe><p>Use jaguar build to generate serializers for newly added JSON serializer.</p><h3>The API</h3><p>With model defined and serialiers for MongoDB and JSON ready, we are all set to define API for CRUD operations.</p><p>Lets define some globals.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e440e61b1d9a9b55f6ba9f2560b01f0/href">https://medium.com/media/9e440e61b1d9a9b55f6ba9f2560b01f0/href</a></iframe><p>Constants mongoUrl and todoColl define the MongoDB URL and collection name for todo model respectively. jsonSerializer and mongoSerializer define the global instances of the corresponding serializers that will be used later in route handlers.</p><p>Empty API class:</p><pre>@Api(path: <strong>&#39;/api/todos&#39;</strong>)<br>@WrapOne(#mongo)<br><strong>class </strong>TodoApi {<br>  MongoDB mongo(Context ctx) =&gt; new MongoDb(mongoUrl);</pre><pre>  //TODO route handlers go here</pre><pre>}</pre><p>@Api declares that the class is Jaguar API and also defines /api/todos as the base path for all the included route handlers.</p><p>@WrapOne route wrapper wraps the MongoDb interceptor around all the routes included in TodoApi . The MongoDB interceptor takes URL to MongoDB database as parameter.</p><p>Lets get into the more juicer part of this blog post.</p><h3>Inserting a document</h3><pre>@Post()<br>Future&lt;Response&lt;String&gt;&gt; insert(Context ctx) <strong>async </strong>{<br>  mgo.Db db = ctx.getInput(MongoDB);<br>  Map body = await ctx.req.bodyAsJsonMap();<br>  TodoItem todo = jsonSerializer.fromMap(body);<br>  <strong>final </strong>String id = <strong>new </strong>mgo.ObjectId().toHexString();<br>  todo.<strong>id </strong>= id;<br>  <strong>final </strong>coll = db.collection(todoColl);<br>  <strong>await </strong>coll.insert(mongoSerializer.toMap(todo));<br><br>  Map res = <strong>await </strong>coll.findOne(mgo.where.id(mgo.ObjectId.<em>parse</em>(id)));<br>  <strong>return </strong>Response.json(mgoToJson(res));<br>}</pre><p>We use ctx.getInput to inject the mongo connection managed by MongoDb interceptor. JSON body of the request is decoded using bodyAsJsonMap member of Request object.</p><pre>TodoItem todo = jsonSerializer.fromMap(body);</pre><p>jsonSerializer is used to decode TodoItem from Map .</p><pre><strong>final </strong>String id = <strong>new </strong>mgo.ObjectId().toHexString();</pre><p>A new ObjectId is created and set for the newly created TodoItem .</p><pre><strong>await </strong>coll.insert(mongoSerializer.toMap(todo));</pre><p>mongoSerializer is used to encode TodoItem to mongo Map and the resulting Map is passed to insert method to insert the new TodoItem into database.</p><h3>Finding a document by Id</h3><pre>@Get(path: &#39;/:id&#39;)  <br>Future&lt;Response&lt;String&gt;&gt; getById(Context ctx) async {    <br>  String id = ctx.pathParams[&#39;id&#39;];   <br>  mgo.Db db = ctx.getInput&lt;mgo.Db&gt;(MongoDb);    <br>  final coll = db.collection(todoColl);    <br>  Map res = await coll.findOne(mgo.where.id(mgo.ObjectId.parse(id)));<br>  return Response.json(_mgoToJson(res));<br>}</pre><p>id path variable is defined to indentify the TodoItem that must be returned.</p><pre>Map res = <strong>await </strong>coll.findOne(mgo.where.id(mgo.ObjectId.<em>parse</em>(id)));</pre><p>mongo-dart ‘s where global function is used to construct the query clause.</p><p>findOne method returns exactly one document matching the requested query.</p><pre>Map _mgoToJson(Map map) =&gt; jsonSerializer.toMap(mongoSerializer.fromMap(map));</pre><p>The convinience method _mgoToJson is used to serialize the mongo Map to JSON Map .</p><h3>Getting all documents</h3><pre>@Get()  <br>Future&lt;Response&lt;String&gt;&gt; getAll(Context ctx) async {    <br>  mgo.Db db = ctx.getInput&lt;mgo.Db&gt;(MongoDb);    <br>  final coll = db.collection(todoColl);    <br>  List&lt;Map&gt; res = await (await coll.find()).map(_mgoToJson).toList();<br>  return Response.json(res);  <br>}</pre><p>find method returns multiple documents matching the supplied optional query. In the absence of query, it returns all documents in the collection.</p><pre><strong>await </strong>coll.find()</pre><p>All TodoItems are mapped from mongo Map to JSON Map using mgoToJson convinience function.</p><h3>Updating a document</h3><pre>@Put()  <br>Future&lt;Response&lt;String&gt;&gt; update(Context ctx) async {    <br>  Map body = await ctx.req.bodyAsJsonMap();    <br>  mgo.Db db = ctx.getInput&lt;mgo.Db&gt;(MongoDb);    <br>  TodoItem todo = jsonSerializer.fromMap(body);    <br>  final String id = todo.id;    <br>  final coll = db.collection(todoColl);    <br>  await coll.update(mgo.where.id(mgo.ObjectId.parse(id)), _mgoEnc(todo));     <br>  Map res = await coll.findOne(mgo.where.id(mgo.ObjectId.parse(id)));    <br>  return Response.json(_mgoToJson(res));  <br>}</pre><p>update method is used to update a document in database. Its first argument defines query limiting the documents that must be updated. In this case just the document with the desired id. The second argument defines the transformations that must be made to update the document. In this case, we just replace the old content with the new content.</p><pre><strong>await </strong>coll.update(mgo.where.id(mgo.ObjectId.<em>parse</em>(id)), _mgoEnc(todo));</pre><h3>Deleting a document</h3><pre>@Delete(path: &#39;/:id&#39;)  <br>Future deleteById(Context ctx) async {    <br>  String id = ctx.pathParams[&#39;id&#39;];    <br>  mgo.Db db = ctx.getInput&lt;mgo.Db&gt;(MongoDb);    <br>  final coll = db.collection(todoColl);    <br>  await coll.remove(mgo.where.id(mgo.ObjectId.parse(id)));  <br>}</pre><p>remove method is used to remove the document from the database.</p><pre><strong>await </strong>coll.remove(mgo.where.id(mgo.ObjectId.<em>parse</em>(id)));</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ca5f7c8e671" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Route paths and path variables in Jaguar.dart]]></title>
            <link>https://medium.com/@tejainece/route-paths-and-path-variables-in-jaguar-dart-344525b94542?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/344525b94542</guid>
            <category><![CDATA[path]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[glob]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <category><![CDATA[variables]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sat, 04 Mar 2017 09:50:26 GMT</pubDate>
            <atom:updated>2018-07-15T20:33:17.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Lets explore the powerful request path matching capabilities of Jaguar in this article.</p><h3>Fixed paths</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1abe22cbb7a4b06b87cd0fd003bf2f5a/href">https://medium.com/media/1abe22cbb7a4b06b87cd0fd003bf2f5a/href</a></iframe><p>The route above uses an <em>exact match</em> of the request path segments.</p><p>The route handler is invoked when a GET request is issued at the URL /api/info.</p><h4>Trailing slashes</h4><p>The route handler is invoked for both /api/info and /api/info/. The trailing slashes are ignored by Jaguar.</p><p>The URIs /api//info and /api///info are also matched, since Jaguar ignores empty path segments.</p><p><strong>Note</strong>: Trailing slashes should not be used to differentiate between actions. The simple path /api/info <strong>will</strong> be matched by a request to /api/info/.</p><h3>Path variables</h3><p>Segments of the path may be matched and extracted with a : prefix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/187b7c532a55d0abf85dd6d374d8d8ad/href">https://medium.com/media/187b7c532a55d0abf85dd6d374d8d8ad/href</a></iframe><p>The :index variable above will match anything except a slash. For example, /api/quote/123 and/api/quote/abc would both be matched by the route above.</p><h4>Position</h4><p>The path variables can appear at any position in the path.</p><p>All the path variables can be accessed using pathParams member of Context instance. pathParams is an instance of PathParams.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aad13b218f3f370d9af2dd7e58405611/href">https://medium.com/media/aad13b218f3f370d9af2dd7e58405611/href</a></iframe><p>The above will match both /api/quote/123/today and/api/quote/abc/today.</p><h4>Multiple variables</h4><p>There could be multiple variables in the same path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4597db7979b7af67f85a3f0aa109f41/href">https://medium.com/media/b4597db7979b7af67f85a3f0aa109f41/href</a></iframe><p>Given the request URL /api/addition/15/10, variables :a and :b shall match 15 and 10 respectively.</p><h3><strong>Type conversion</strong></h3><p>Path variables can be converted to one of the supported target types (int , num, double and bool) using one of the get* methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2411aa8396777d6723d3ed95bac2d13b/href">https://medium.com/media/2411aa8396777d6723d3ed95bac2d13b/href</a></iframe><p>Path variable index is converted to int using int.parse function.</p><h3>Glob path segment</h3><p>A star can be used to match all the following path segments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4cea6def47c9c40657d3e503895e947/href">https://medium.com/media/d4cea6def47c9c40657d3e503895e947/href</a></iframe><p>The route handler will match any path that begins with /api/1/ .</p><h3>Captured Glob variable</h3><p>Starred path variable can be used to match all the remaining path segments while also capturing the path segments it is matching.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/152e74991a1d5ba4e006efb7be67f3e1/href">https://medium.com/media/152e74991a1d5ba4e006efb7be67f3e1/href</a></iframe><p>For example, the route handler will match any path beginning with /api/1/. The value of variable path will be the path sub-string that follows the matched /api/1/. If the request URL is /api/1/what/ever , path will hold what/ever .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=344525b94542" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Controllers]]></title>
            <link>https://medium.com/@tejainece/jaguar-dart-has-multiple-personality-dis-order-1133f3894dad?source=rss-870a21a0e195------2</link>
            <guid isPermaLink="false">https://medium.com/p/1133f3894dad</guid>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[route-handler]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[jaguar-dart]]></category>
            <dc:creator><![CDATA[Ravi Teja Gudapati]]></dc:creator>
            <pubDate>Sat, 04 Mar 2017 04:08:51 GMT</pubDate>
            <atom:updated>2018-07-15T20:32:10.135Z</atom:updated>
            <content:encoded><![CDATA[<p>Controllers are great way to group related routes under the same class. This is a modern, intuitive and declarative way of wiring up routes.</p><p>The Controller shall be tagged with Controller annotation for Jaguar to recognize it.</p><pre>@Controller(path: &#39;/books&#39;)<br>class BookRoutes {<br> // Add route handlers here<br>}</pre><p>Routes handlers are simple methods in a <em>Controller</em> class. They shall be tagged on of the HTTP method annotation for Jaguar to recognize them. The available HTTP methods are: <em>@Get()</em>, <em>@Post()</em>, <em>@Put()</em>, <em>@Delete(), @GetJson(), @PostJson(), @PutJson(), @DeleteJson(), etc.</em></p><pre>@Controller(path: &#39;/books&#39;)<br>class BookRoutes {<br>  @GetJson()<br>  List&lt;Book&gt; getAll(Context ctx) =&gt; books.values.toList();<br>  <br>  // Add more route handlers here<br>}</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c58aea6235aa630a636ec0a08eeab8d/href">https://medium.com/media/6c58aea6235aa630a636ec0a08eeab8d/href</a></iframe><p>Adding a Controller to the Jaguar server is done using add method. Use the reflect function of jaguar_reflect package to build a RequestHandler from the Controller specification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35ffa4d082b5d70361abab96def1a865/href">https://medium.com/media/35ffa4d082b5d70361abab96def1a865/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1133f3894dad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>