{"id":135283,"date":"2024-09-05T15:40:58","date_gmt":"2024-09-05T10:10:58","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=135283"},"modified":"2024-09-05T15:40:59","modified_gmt":"2024-09-05T10:10:59","slug":"introduction-to-rest","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/","title":{"rendered":"Introduction to REST"},"content":{"rendered":"\n<p>REST (Representational State Transfer) is a software architectural style that defines a set of constraints for creating web services. It&#8217;s based on the principles of HTTP and leverages the stateless nature of web interactions. \u00a0<a href=\"https:\/\/github.com\/Ahammad204\/Ph-tube\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/github.com\/Ahammad204\/Ph-tube\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Key Principles of REST<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Statelessness:<\/strong> Each request is treated independently, without relying on previous requests.<\/li>\n\n\n\n<li><strong>Client-Server Architecture:<\/strong> The client (e.g., a web browser) sends requests to the server, which processes them and returns a response.<\/li>\n\n\n\n<li><strong>Cacheability:<\/strong> Responses can be cached to improve performance and reduce server load.<\/li>\n\n\n\n<li><strong>Layered System:<\/strong> The architecture is layered, allowing for flexibility and scalability.<\/li>\n\n\n\n<li><strong>Uniform Interface:<\/strong> RESTful APIs use a uniform interface, defined by a set of operations (GET, POST, PUT, PATCH, DELETE) and resources.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>RESTful APIs and FastAPI<\/strong><\/h3>\n\n\n\n<p>FastAPI is a Python framework that is well-suited for building RESTful APIs. It provides a clean and concise syntax, making it easy to implement REST principles.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Common HTTP Methods and Their Use in FastAPI<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GET:<\/strong> Retrieves data from the server.<\/li>\n\n\n\n<li><strong>POST:<\/strong> Creates new data on the server.<\/li>\n\n\n\n<li><strong>PUT:<\/strong> Updates existing data on the server.<\/li>\n\n\n\n<li><strong>PATCH:<\/strong> Partially updates existing data on the server.<\/li>\n\n\n\n<li><strong>DELETE:<\/strong> Deletes data from the server.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example of a RESTful API Using FastAPI<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from fastapi import FastAPI\nfrom pydantic import BaseModel\n\napp = FastAPI()\n\nclass Item(BaseModel):\n    name: str\n    price: float\n\n@app.get(\"\/items\/{item_id}\") \u00a0 <a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\"> 1.  medium.com <\/a><a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\">medium.com<\/a><a href=\"https:\/\/medium.com\/featurepreneur\/why-fastapi-69fb172756b7\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\nasync def read_item(item_id: int):\n    return {\"item_id\": item_id}\n\n@app.post(\"\/items\/\")\nasync def create_item(item: Item): \u00a0 <a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\"> 1.  github.com <\/a><a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\">github.com<\/a><a href=\"https:\/\/github.com\/rugbyprof\/5303-Adv-Database\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\n    return item<\/code><\/pre>\n\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Item<\/code> is a Pydantic model representing an item.<\/li>\n\n\n\n<li><code>@app.get(\"\/items\/{item_id}\")<\/code> defines a GET endpoint for retrieving an item by ID.<\/li>\n\n\n\n<li><code>@app.post(\"\/items\/\")<\/code> defines a POST endpoint for creating a new item.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Best Practices for RESTful API Design<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use meaningful URLs:<\/strong> URLs should reflect the resources they represent.<\/li>\n\n\n\n<li><strong>Leverage HTTP methods appropriately:<\/strong> Use the correct HTTP method for each operation.<\/li>\n\n\n\n<li><strong>Return appropriate status codes:<\/strong> Use HTTP status codes to indicate the outcome of requests.<\/li>\n\n\n\n<li><strong>Provide clear documentation:<\/strong> Use tools like Swagger or OpenAPI to generate documentation.<\/li>\n\n\n\n<li><strong>Consider versioning:<\/strong> If you need to make significant changes to your API, consider versioning.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>REST (Representational State Transfer) is a software architectural style that defines a set of constraints for creating web services. It&#8217;s based on the principles of HTTP and leverages the stateless nature of web interactions. \u00a0 Key Principles of REST RESTful APIs and FastAPI FastAPI is a Python framework that is well-suited for building RESTful APIs&#8230;.<\/p>\n","protected":false},"author":16,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-135283","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introduction to REST - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to REST - Tutorial\" \/>\n<meta property=\"og:description\" content=\"REST (Representational State Transfer) is a software architectural style that defines a set of constraints for creating web services. It&#8217;s based on the principles of HTTP and leverages the stateless nature of web interactions. \u00a0 Key Principles of REST RESTful APIs and FastAPI FastAPI is a Python framework that is well-suited for building RESTful APIs....\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-05T10:10:59+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/\",\"name\":\"Introduction to REST - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2024-09-05T10:10:58+00:00\",\"dateModified\":\"2024-09-05T10:10:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to REST\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to REST - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to REST - Tutorial","og_description":"REST (Representational State Transfer) is a software architectural style that defines a set of constraints for creating web services. It&#8217;s based on the principles of HTTP and leverages the stateless nature of web interactions. \u00a0 Key Principles of REST RESTful APIs and FastAPI FastAPI is a Python framework that is well-suited for building RESTful APIs....","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-09-05T10:10:59+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/","name":"Introduction to REST - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2024-09-05T10:10:58+00:00","dateModified":"2024-09-05T10:10:59+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-rest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Introduction to REST"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/135283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=135283"}],"version-history":[{"count":2,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/135283\/revisions"}],"predecessor-version":[{"id":135287,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/135283\/revisions\/135287"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=135283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=135283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=135283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}