{"id":189279,"date":"2025-02-09T03:29:20","date_gmt":"2025-02-09T03:29:20","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=189279"},"modified":"2025-02-09T03:29:22","modified_gmt":"2025-02-09T03:29:22","slug":"good-uri-design-which-of-the-following-rules-should-be-followed-to-design-a-good-uri","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/02\/09\/good-uri-design-which-of-the-following-rules-should-be-followed-to-design-a-good-uri\/","title":{"rendered":"Good URI Design Which of the following rules should be followed to design a good URI"},"content":{"rendered":"\n<p>\u00a0Good URI Design Which of the following rules should be followed to design a good URI? Pick ONE OR MORE options URIs should never be changed URIs must be constructed by the client URIs should be short in length URIs should be case-sensitive HTTP verbs should be used instead of operation names in URIs Use spaces when designing a URI Redirection must be used if a change in URI is required<\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-6-color\">The correct answer and explanation is:<\/mark><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Correct Answers:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>URIs should be short in length<\/strong><\/li>\n\n\n\n<li><strong>HTTP verbs should be used instead of operation names in URIs<\/strong><\/li>\n\n\n\n<li><strong>Redirection must be used if a change in URI is required<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Explanation<\/strong><\/h3>\n\n\n\n<p>A <strong>Uniform Resource Identifier (URI)<\/strong> is a key component of web APIs and web resources. A well-designed URI ensures usability, clarity, and longevity. Below is an explanation of why certain URI design principles should be followed:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. URIs Should Be Short in Length<\/strong><\/h4>\n\n\n\n<p>Short URIs are easier to read, remember, and type. Long, complex URIs increase the risk of errors and reduce usability. A well-structured, concise URI enhances user experience and improves SEO for websites. For example:<br>\u2705 <strong>Good:<\/strong> <code>https:\/\/api.example.com\/products\/123<\/code><br>\u274c <strong>Bad:<\/strong> <code>https:\/\/api.example.com\/store\/products\/category\/electronics\/brand\/samsung\/item\/12345\/details<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. HTTP Verbs Should Be Used Instead of Operation Names in URIs<\/strong><\/h4>\n\n\n\n<p>RESTful APIs should use HTTP methods (<code>GET<\/code>, <code>POST<\/code>, <code>PUT<\/code>, <code>DELETE<\/code>) rather than embedding operations in URIs. This makes the API more intuitive and adheres to REST principles.<br>\u2705 <strong>Good:<\/strong> <code>GET \/users\/123<\/code> (to fetch user details)<br>\u274c <strong>Bad:<\/strong> <code>GET \/getUserById\/123<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Redirection Must Be Used If a Change in URI is Required<\/strong><\/h4>\n\n\n\n<p>URIs should be stable over time, but if a change is unavoidable, <strong>HTTP 301 (Moved Permanently)<\/strong> or <strong>HTTP 302 (Found\/Redirect)<\/strong> must be used to ensure proper redirection. This helps maintain backward compatibility and avoids breaking existing links.<br>\u2705 <strong>Good:<\/strong> Redirecting <code>\/old-url<\/code> \u2192 <code>\/new-url<\/code> using HTTP 301<br>\u274c <strong>Bad:<\/strong> Simply removing the old URI, causing a 404 error<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Incorrect Options &amp; Why They Are Wrong<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>&#8220;URIs should never be changed&#8221;<\/strong> \u2192 While stability is important, sometimes URIs need to be updated for better clarity or organization. Redirection should be used in such cases.<\/li>\n\n\n\n<li><strong>&#8220;URIs must be constructed by the client&#8221;<\/strong> \u2192 Clients should not create URIs dynamically; they should use predefined endpoints from the API documentation.<\/li>\n\n\n\n<li><strong>&#8220;URIs should be case-sensitive&#8221;<\/strong> \u2192 While technically possible, it&#8217;s not recommended as it can cause confusion (<code>\/Product<\/code> vs <code>\/product<\/code>). Best practice is to use lowercase.<\/li>\n\n\n\n<li><strong>&#8220;Use spaces when designing a URI&#8221;<\/strong> \u2192 Spaces are invalid in URIs and require encoding (<code>%20<\/code>), which makes them harder to read. Instead, use hyphens (<code>-<\/code>) or underscores (<code>_<\/code>).<\/li>\n<\/ul>\n\n\n\n<p>By following these best practices, URIs remain readable, scalable, and maintainable. \ud83d\ude80<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0Good URI Design Which of the following rules should be followed to design a good URI? Pick ONE OR MORE options URIs should never be changed URIs must be constructed by the client URIs should be short in length URIs should be case-sensitive HTTP verbs should be used instead of operation names in URIs Use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-189279","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/189279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=189279"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/189279\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=189279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=189279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=189279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}