zoukankan      html  css  js  c++  java
  • Using HTTP Methods for RESTful Services

    https://www.restapitutorial.com/lessons/httpmethods.html

    Using HTTP Methods for RESTful Services

    The HTTP verbs comprise a major portion of our “uniform interface” constraint and provide us the action counterpart to the noun-based resource. The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively. There are a number of other verbs, too, but are utilized less frequently. Of those less-frequent methods, OPTIONS and HEAD are used more often than others.

    Below is a table summarizing recommended return values of the primary HTTP methods in combination with the resource URIs:

    HTTP VerbCRUDEntire Collection (e.g. /customers)Specific Item (e.g. /customers/{id})
    POST Create 201 (Created), 'Location' header with link to /customers/{id} containing new ID. 404 (Not Found), 409 (Conflict) if resource already exists..
    GET Read 200 (OK), list of customers. Use pagination, sorting and filtering to navigate big lists. 200 (OK), single customer. 404 (Not Found), if ID not found or invalid.
    PUT Update/Replace 405 (Method Not Allowed), unless you want to update/replace every resource in the entire collection. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
    PATCH Update/Modify 405 (Method Not Allowed), unless you want to modify the collection itself. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
    DELETE Delete 405 (Method Not Allowed), unless you want to delete the whole collection—not often desirable. 200 (OK). 404 (Not Found), if ID not found or invalid.

    Below is a more-detailed discussion of the main HTTP methods. Click on a tab for more information about the desired HTTP method.

    The POST verb is most-often utilized to **create** new resources. In particular, it's used to create subordinate resources. That is, subordinate to some other (e.g. parent) resource. In other words, when creating a new resource, POST to the parent and the service takes care of associating the new resource with the parent, assigning an ID (new resource URI), etc.

    On successful creation, return HTTP status 201, returning a Location header with a link to the newly-created resource with the 201 HTTP status.

    POST is neither safe nor idempotent. It is therefore recommended for non-idempotent resource requests. Making two identical POST requests will most-likely result in two resources containing the same information.

    Examples:

    • POST http://www.example.com/customers
    • POST http://www.example.com/customers/12345/orders
    What Doesn't Kill Me Makes Me Stronger
  • 相关阅读:
    ylb: SQL表的高级查询-子查询
    ylb:SQL 系统函数
    ylb:SQL 常用函数
    ylb:exists(存在)的应用实例
    ylb:子查询(嵌套子查询)和子查询(相关子查询)
    ylb:多表的连接与练习(第三方关联表的应用)
    ylb:表的结构的修改和基本约束
    ylb:SQL Server中的escape(逃逸)
    ylb:SQL Server中的时间函数
    ylb:创建数据库、表,对表的增查改删语句
  • 原文地址:https://www.cnblogs.com/kungfupanda/p/14383761.html
Copyright © 2011-2022 走看看