{"id":1108,"date":"2017-10-12T18:46:16","date_gmt":"2017-10-12T15:46:16","guid":{"rendered":"https:\/\/community.virtono.com\/?p=1108"},"modified":"2020-06-10T16:53:26","modified_gmt":"2020-06-10T13:53:26","slug":"rest","status":"publish","type":"post","link":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/rest\/","title":{"rendered":"REST"},"content":{"rendered":"<header class=\"entry-header\">\n<h3 id=\"seriesName\">Series:\u00a0Introduction to the MEAN Stack<\/h3>\n<ul id=\"seriesList\">\n<li><a href=\"https:\/\/wp.me\/p7ISfL-hs\" target=\"_blank\" rel=\"noopener\">Part 1: Definition of the MEAN stack<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/p7ISfL-hz\" target=\"_blank\" rel=\"noopener\">Part 2:\u00a0Setup of the MEAN stack<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/p7ISfL-hC\" target=\"_blank\" rel=\"noopener\">Part 3:\u00a0Node.js<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-npm\" target=\"_blank\" rel=\"noopener\">Part 4:\u00a0npm<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-connect\" target=\"_blank\" rel=\"noopener\">Part 5:\u00a0Connect<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-express\" target=\"_blank\" rel=\"noopener\">Part 6:\u00a0Express<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-mongodb\" target=\"_blank\" rel=\"noopener\">Part 7:\u00a0MongoDB<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-mongodb\" target=\"_blank\" rel=\"noopener\">Part 8:\u00a0Mongoose<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-rest\" target=\"_blank\" rel=\"noopener\">Part 9:\u00a0REST<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-baucis\" target=\"_blank\" rel=\"noopener\">Part 10:\u00a0Baucis<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/s7ISfL-bower\" target=\"_blank\" rel=\"noopener\">Part 11:\u00a0Bower<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/p7ISfL-i1\" target=\"_blank\" rel=\"noopener\">Part 12:\u00a0AngularJS<\/a><\/li>\n<li><a href=\"https:\/\/wp.me\/p7ISfL-i4\" target=\"_blank\" rel=\"noopener\">Part 13:\u00a0Restangular<\/a><\/li>\n<\/ul>\n<\/header>\n<div class=\"entry-content\">\n<p>Today you will\u00a0find\u00a0a major theoretical article about\u00a0REST\u00a0and why this concept is so important.\u00a0This article will be the basis for our later server API.<span id=\"more-3642\"><\/span><\/p>\n<p>REST or a RESTful API is a concept to exchange and manipulate data between the database via a server with a client using HTTP requests.\u00a0The abbreviation REST stands for Representational State Transfer.\u00a0For this purpose, the method names of HTTP are called a\u00a0<strong>CRUD<\/strong>Functionality.\u00a0This is for Create, Read, Update, and Delete, and represents the basic operations that you can apply to data. The required data is described through a URL, each containing a URL for a collection of data and a URL for a single record from this collection.\u00a0(Note: Even if I use terms from the NoSQL world to explain the REST concept, REST can also be used with classic SQL databases.) However, not all CRUD commands can be applied to these URLs.\u00a0This results in the following concept:<\/p>\n<table>\n<tbody>\n<tr>\n<th>HTTP method<\/th>\n<th>URL Collection:\u00a0<code class=\"codecolorer powershell default\"><span class=\"powershell\"><span class=\"sy0\">\/<\/span><span class=\"br0\">{<\/span>collection<span class=\"br0\">}<\/span><\/span><\/code><\/th>\n<th>URL Document:\u00a0<code class=\"codecolorer powershell default\"><span class=\"powershell\"><span class=\"sy0\">\/<\/span><span class=\"br0\">{<\/span>collection<span class=\"br0\">}<\/span><span class=\"sy0\">\/<\/span><span class=\"br0\">{<\/span>id<span class=\"br0\">}<\/span><\/span><\/code><\/th>\n<\/tr>\n<tr>\n<td>POST (Create)<\/td>\n<td>Creates a new document for this collection.<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>GET (Read)<\/td>\n<td>Returns multiple documents from the collection.<\/td>\n<td>Returns a single document.<\/td>\n<\/tr>\n<tr>\n<td>PUT (Update)<\/td>\n<td>&#8211;<\/td>\n<td>Updated a single document.<\/td>\n<\/tr>\n<tr>\n<td>DELETE (Remove)<\/td>\n<td>Deletes multiple documents in the collection.<\/td>\n<td>Deletes a single document.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This concept can also be used to map hierarchies.\u00a0Suppose we have a collection for blog articles and for readers with a 1-to-n relationship (an article has any number of comments).\u00a0So you could\u00a0\u00a0address\u00a0with the URL\u00a0the second comment of the first article.\u00a0More fine filters could be set via query parameters.\u00a0If you want to address all blog article by a certain authors from 2010 to 2012, the corresponding URL could potentially look like this:\u00a0.\u00a0This is not necessarily the URL that your reader&#8217;s readers see and use, but the URL that the client uses to get the corresponding record.<code class=\"codecolorer powershell default\"><span class=\"powershell\"><span class=\"sy0\">\/<\/span>articles<span class=\"sy0\">\/<\/span><span class=\"nu0\">1<\/span><span class=\"sy0\">\/<\/span>comments<span class=\"sy0\">\/<\/span><span class=\"nu0\">2<\/span><\/span><\/code><code class=\"codecolorer powershell default\"><span class=\"powershell\"><span class=\"sy0\">\/<\/span>articles<span class=\"sy0\">?<\/span>author<span class=\"sy0\">=<\/span>Pipo<span class=\"sy0\">&amp;<\/span>from<span class=\"sy0\">=<\/span><span class=\"nu0\">2010<\/span><span class=\"sy0\">&amp;<\/span>to<span class=\"sy0\">=<\/span><span class=\"nu0\">2012<\/span><\/span><\/code><\/p>\n<p>This is a\u00a0<i>very<\/i>\u00a0brief explanation for the REST concept, which should be sufficient for a basic understanding.\u00a0The idea of REST was formulated by Roy Fielding in his dissertation 2000.<\/p>\n<p>Now one could ask the question what we need REST at all?\u00a0Finally, our previous examples have already shown how to send data from the database via the server to the client.\u00a0There are many reasons for REST: REST allows not only a simple query of the data from the database to the client, but also the manipulation of this data &#8211; the way in the other direction.\u00a0Since REST is based on HTTP, it is also universally applicable.\u00a0Assuming next to a webapplication, you also want to develop a native app for iOS or Android.\u00a0With REST, you can use the same server and the same database for both the Web and native app.\u00a0You do not have to make any code changes on the server side for different clients.\u00a0As a further reason, REST allows for the simple\u00a0\u00a0<i>downsizing<\/i>load data and thus much more dynamic surfaces (keyword: AJAX).\u00a0In the end, REST is an easy-to-understand interface.\u00a0The limitation to CRUD commands limits the scope of the API when creating the API, but on the other hand, the API remains as clear and similar to other platform APIs.\u00a0Once you have used a REST API, you will quickly find your way to other REST APIs.<\/p>\n<p>According to this theoretical article, we will use the REST concept next time!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Series:\u00a0Introduction to the MEAN Stack Part 1: Definition of the MEAN stack Part 2:\u00a0Setup of the MEAN stack Part 3:\u00a0Node.js Part 4:\u00a0npm Part 5:\u00a0Connect Part 6:\u00a0Express Part 7:\u00a0MongoDB Part 8:\u00a0Mongoose Part 9:\u00a0REST Part 10:\u00a0Baucis Part 11:\u00a0Bower Part 12:\u00a0AngularJS Part 13:\u00a0Restangular Today you will\u00a0find\u00a0a major theoretical article about\u00a0REST\u00a0and why this concept<\/p>\n","protected":false},"author":4,"featured_media":1109,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5,3],"tags":[],"class_list":["post-1108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase","category-tutorial-how-to"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/use-nodejs-to-create-a-rest-api-7-638.jpg?fit=638%2C493&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s7ISfL-rest","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1082,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/definition-of-the-mean-stack\/","url_meta":{"origin":1108,"position":0},"title":"Definition of the MEAN stack","author":"Shreyash Sharma","date":"October 9, 2017","format":false,"excerpt":"Series:\u00a0Introduction to the MEAN Stack Part 1: Definition of the MEAN stack Part 2:\u00a0Setup of the MEAN stack Part 3:\u00a0Node.js Part 4:\u00a0npm Part 5:\u00a0Connect Part 6:\u00a0Express Part 7:\u00a0MongoDB Part 8:\u00a0Mongoose Part 9:\u00a0REST Part 10:\u00a0Baucis Part 11:\u00a0Bower Part 12:\u00a0AngularJS Part 13:\u00a0Restangular In a new article series, I would like to\u00a0offer\u00a0you an\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/Mean.jpg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/Mean.jpg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/Mean.jpg?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/Mean.jpg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/Mean.jpg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3507,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-lemp-stack-linux-nginx-mysql-and-php-on-ubuntu-22-04\/","url_meta":{"origin":1108,"position":1},"title":"How to install LEMP stack (Linux, Nginx, MySQL, and PHP) on Ubuntu 22.04","author":"George B.","date":"June 20, 2023","format":false,"excerpt":"Introduction The LEMP stack is a popular software stack for web development and hosting. It includes four major components: Linux, Nginx, MySQL, and PHP. Each component serves a specific purpose in powering dynamic websites and web applications. Linux is the operating system that serves as the LEMP stack's foundation. In\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/06\/How-to-install-LEMP-stack-Linux-Nginx-MySQL-PHP-on-Ubuntu-22-04.png?fit=600%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/06\/How-to-install-LEMP-stack-Linux-Nginx-MySQL-PHP-on-Ubuntu-22-04.png?fit=600%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/06\/How-to-install-LEMP-stack-Linux-Nginx-MySQL-PHP-on-Ubuntu-22-04.png?fit=600%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1089,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/setup-of-the-mean-stack\/","url_meta":{"origin":1108,"position":2},"title":"Setup of the MEAN stack","author":"Daniel Draga","date":"October 9, 2017","format":false,"excerpt":"Series:\u00a0Introduction to the MEAN Stack Part 1: Definition of the MEAN stack Part 2:\u00a0Setup of the MEAN stack Part 3:\u00a0Node.js Part 4:\u00a0npm Part 5:\u00a0Connect Part 6:\u00a0Express Part 7:\u00a0MongoDB Part 8:\u00a0Mongoose Part 9:\u00a0REST Part 10:\u00a0Baucis Part 11:\u00a0Bower Part 12:\u00a0AngularJS Part 13:\u00a0Restangular In this article, we will lay out the basics for\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/meanjs-1024x492.png?fit=1024%2C492&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/meanjs-1024x492.png?fit=1024%2C492&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/meanjs-1024x492.png?fit=1024%2C492&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/meanjs-1024x492.png?fit=1024%2C492&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1256,"url":"https:\/\/www.virtono.com\/community\/internet-and-technology-news\/google-disassembles-usb-stack-of-the-linux-kernel\/","url_meta":{"origin":1108,"position":3},"title":"Google disassembles USB stack of the Linux kernel","author":"Daniel Draga","date":"November 9, 2017","format":false,"excerpt":"With a special fuzzer for kernel system calls from\u00a0Google\u00a0, extremely many bugs have been found in the USB stack of the\u00a0Linux kernel\u00a0.\u00a0Many of them are classified as critical vulnerabilities, which is true for all kernel bugs. The Syzkaller tool, created and developed with Google support, is intended to fuzzy operating\u2026","rel":"","context":"In &quot;IT News&quot;","block_context":{"text":"IT News","link":"https:\/\/www.virtono.com\/community\/category\/internet-and-technology-news\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/11\/google-linux.png?fit=1200%2C569&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/11\/google-linux.png?fit=1200%2C569&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/11\/google-linux.png?fit=1200%2C569&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/11\/google-linux.png?fit=1200%2C569&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/11\/google-linux.png?fit=1200%2C569&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":376,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/set-up-a-lamp-stack-on-ubuntu-14-04\/","url_meta":{"origin":1108,"position":4},"title":"Set up a LAMP stack on Ubuntu 14.04","author":"Daniel Draga","date":"August 11, 2016","format":false,"excerpt":"Introduction The LAMP stack (Linux, Apache, MySQL, PHP) is a group of open source software that is typically installed together to enable a server to host dynamic PHP websites and web apps. This guide includes the steps to set up a LAMP stack on Ubuntu 14.04, if you want more\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/08\/pic.jpg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/08\/pic.jpg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/08\/pic.jpg?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/08\/pic.jpg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/08\/pic.jpg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1092,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/node-js\/","url_meta":{"origin":1108,"position":5},"title":"Node.js","author":"Daniel Draga","date":"October 10, 2017","format":false,"excerpt":"Series:\u00a0Introduction to the MEAN Stack Part 1: Definition of the MEAN stack Part 2:\u00a0Setup of the MEAN stack Part 3:\u00a0Node.js Part 4:\u00a0npm Part 5:\u00a0Connect Part 6:\u00a0Express Part 7:\u00a0MongoDB Part 8:\u00a0Mongoose Part 9:\u00a0REST Part 10:\u00a0Baucis Part 11:\u00a0Bower Part 12:\u00a0AngularJS Part 13:\u00a0Restangular In this article, I tell you what\u00a0Node.js is\u00a0exactly and what\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/nodejs-new-pantone-black.png?fit=1200%2C735&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/nodejs-new-pantone-black.png?fit=1200%2C735&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/nodejs-new-pantone-black.png?fit=1200%2C735&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/nodejs-new-pantone-black.png?fit=1200%2C735&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/nodejs-new-pantone-black.png?fit=1200%2C735&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/comments?post=1108"}],"version-history":[{"count":2,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1108\/revisions"}],"predecessor-version":[{"id":1181,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1108\/revisions\/1181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media\/1109"}],"wp:attachment":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media?parent=1108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/categories?post=1108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/tags?post=1108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}