<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>devkuma – REST API</title>
    <link>https://www.devkuma.com/en/tags/rest-api/</link>
    <image>
      <url>https://www.devkuma.com/en/tags/rest-api/logo/180x180.jpg</url>
      <title>REST API</title>
      <link>https://www.devkuma.com/en/tags/rest-api/</link>
    </image>
    <description>Recent content in REST API on devkuma</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>kc@example.com (kc kim)</managingEditor>
    <webMaster>kc@example.com (kc kim)</webMaster>
    <copyright>The devkuma</copyright>
    
	  <atom:link href="https://www.devkuma.com/en/tags/rest-api/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>REST API</title>
      <link>https://www.devkuma.com/en/docs/rest-api/</link>
      <pubDate>Mon, 25 Dec 2017 19:03:56 +0900</pubDate>
      <author>kc@example.com (kc kim)</author>
      <guid>https://www.devkuma.com/en/docs/rest-api/</guid>
      <description>
        
        
        &lt;h2 id=&#34;what-is-rest&#34;&gt;What Is REST?&lt;/h2&gt;
&lt;p&gt;REST stands for Representational State Transfer. It is an architectural style for distributed hypermedia systems such as the World Wide Web. Roy Fielding introduced REST in his 2000 doctoral dissertation. Systems that follow REST principles are often described as RESTful.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.devkuma.com/docs/rest-api/rest-api.png&#34; alt=&#34;REST API&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;rest-characteristics&#34;&gt;REST Characteristics&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Uniform interface&lt;/strong&gt;: Resources are manipulated through a consistent and limited interface identified by URIs. An HTTP API is not tied to a specific platform or programming language.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Statelessness&lt;/strong&gt;: Each request contains the information needed to process it. The server does not need to maintain client session state between requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cacheability&lt;/strong&gt;: REST uses HTTP infrastructure and can benefit from caching through headers such as &lt;code&gt;Last-Modified&lt;/code&gt; and &lt;code&gt;ETag&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Client-server architecture&lt;/strong&gt;: Clients and servers have distinct responsibilities, reducing dependencies between them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Self-descriptive messages&lt;/strong&gt;: A request or response should contain enough information to explain how it must be processed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Layered system&lt;/strong&gt;: Security, load balancing, encryption, proxies, and gateways can be introduced as intermediate layers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code on demand (optional)&lt;/strong&gt;: A server may extend client behavior by sending executable logic such as JavaScript.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;rest-components&#34;&gt;REST Components&lt;/h2&gt;
&lt;h3 id=&#34;resource&#34;&gt;Resource&lt;/h3&gt;
&lt;p&gt;A resource is an identifiable entity stored by the server. Clients request or modify its state through a URI such as &lt;code&gt;/groups/{groupId}/users/{userId}&lt;/code&gt;. Resource names are usually nouns such as &lt;code&gt;users&lt;/code&gt; or &lt;code&gt;groups&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;method&#34;&gt;Method&lt;/h3&gt;
&lt;p&gt;An HTTP method expresses the action to perform on a resource. Common methods include &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, and &lt;code&gt;DELETE&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;representation&#34;&gt;Representation&lt;/h3&gt;
&lt;p&gt;A representation is the form of a resource sent in a response. A resource may be represented as JSON, XML, text, or another media type.&lt;/p&gt;
&lt;h2 id=&#34;http-methods&#34;&gt;HTTP Methods&lt;/h2&gt;
&lt;p&gt;REST APIs commonly map HTTP methods to CRUD operations.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;HTTP method&lt;/th&gt;
					&lt;th&gt;CRUD&lt;/th&gt;
					&lt;th&gt;Collection, such as &lt;code&gt;/customers&lt;/code&gt;&lt;/th&gt;
					&lt;th&gt;Item, such as &lt;code&gt;/customers/{id}&lt;/code&gt;&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;POST&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Create&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;201 Created&lt;/code&gt;, usually with a &lt;code&gt;Location&lt;/code&gt; header&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;404 Not Found&lt;/code&gt; or &lt;code&gt;409 Conflict&lt;/code&gt; if the resource already exists&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;GET&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Read&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;200 OK&lt;/code&gt;, returning a list with pagination, sorting, or filtering as needed&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;200 OK&lt;/code&gt;, or &lt;code&gt;404 Not Found&lt;/code&gt; for an unknown ID&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;PUT&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Update or replace&lt;/td&gt;
					&lt;td&gt;Usually &lt;code&gt;405 Method Not Allowed&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;200 OK&lt;/code&gt; or &lt;code&gt;204 No Content&lt;/code&gt;, or &lt;code&gt;404 Not Found&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;DELETE&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Delete&lt;/td&gt;
					&lt;td&gt;Usually &lt;code&gt;405 Method Not Allowed&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;200 OK&lt;/code&gt;, or &lt;code&gt;404 Not Found&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;resource-naming&#34;&gt;Resource Naming&lt;/h2&gt;
&lt;p&gt;Two core rules guide REST resource naming:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A URI represents a resource.&lt;/li&gt;
&lt;li&gt;An HTTP method represents the action on that resource.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;use-nouns-for-resources&#34;&gt;Use Nouns for Resources&lt;/h3&gt;
&lt;p&gt;Do not encode actions such as &lt;code&gt;update&lt;/code&gt; in the URI.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;GET /users/update/1  (X)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;PUT /users/1         (O)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;prefer-plural-resource-names&#34;&gt;Prefer Plural Resource Names&lt;/h3&gt;
&lt;p&gt;Use plural nouns consistently for URI path segments.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;GET /user/329   (X)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;GET /users/329  (O)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;do-not-include-file-extensions&#34;&gt;Do Not Include File Extensions&lt;/h3&gt;
&lt;p&gt;Use an HTTP header such as &lt;code&gt;Accept&lt;/code&gt; to request a representation.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;GET /users/345/profile.jpg                          (X)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;GET /users/345/profile
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Accept: image/jpeg                                  (O)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;use-slashes-for-hierarchy&#34;&gt;Use Slashes for Hierarchy&lt;/h3&gt;
&lt;p&gt;Use &lt;code&gt;/&lt;/code&gt; to express hierarchy, but avoid a trailing slash.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/users/{userId}/books/  (X)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/users/{userId}/books   (O)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;express-relationships-between-resources&#34;&gt;Express Relationships Between Resources&lt;/h3&gt;
&lt;p&gt;Subresources can describe relationships.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/users/{userId}/friends
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/users/{userId}/books
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/users/{userId}/recommendations/books
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;prefer-lowercase-paths&#34;&gt;Prefer Lowercase Paths&lt;/h3&gt;
&lt;p&gt;URI paths are case-sensitive outside the scheme and host. Lowercase paths avoid ambiguity.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/Users/{userId}/Books  (X)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/users/{userId}/books  (O)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;http-status-codes&#34;&gt;HTTP Status Codes&lt;/h2&gt;
&lt;p&gt;A well-designed REST API returns meaningful HTTP status codes.&lt;/p&gt;
&lt;h3 id=&#34;2xx-success&#34;&gt;2xx Success&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Code&lt;/th&gt;
					&lt;th&gt;Meaning&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;200 OK&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The request was processed successfully.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;201 Created&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;A new resource was created successfully.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;204 No Content&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The request succeeded and no response body is needed.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;3xx-redirection&#34;&gt;3xx Redirection&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Code&lt;/th&gt;
					&lt;th&gt;Meaning&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;304 Not Modified&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The requested resource has not changed since the client&amp;rsquo;s cached version.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;4xx-client-error&#34;&gt;4xx Client Error&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Code&lt;/th&gt;
					&lt;th&gt;Meaning&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;400 Bad Request&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The server could not understand the request syntax.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;401 Unauthorized&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Authentication is required or failed.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;403 Forbidden&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The server understood the request but refuses access.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;404 Not Found&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The requested resource does not exist.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;5xx-server-error&#34;&gt;5xx Server Error&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Code&lt;/th&gt;
					&lt;th&gt;Meaning&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;500 Internal Server Error&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The server encountered an error while processing the request.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/REST&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Wikipedia | REST&lt;i class=&#34;fas fa-external-link-alt&#34;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/List_of_HTTP_status_codes&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Wikipedia | List of HTTP status codes&lt;i class=&#34;fas fa-external-link-alt&#34;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.restapitutorial.com/lessons/restfulresourcenaming.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RESTful Resource Naming&lt;i class=&#34;fas fa-external-link-alt&#34;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </description>
      
      <category>WEB</category>
      
      <category>REST API</category>
      
    </item>
    
  </channel>
</rss>
