差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 下次修改 Both sides next revision | ||
java:web:restapi [2017/09/18 23:49] tony [Articles] |
java:web:restapi [2022/06/12 14:47] tony [Articles] |
||
---|---|---|---|
行 1: | 行 1: | ||
{{tag>rest}} | {{tag>rest}} | ||
- | ====== Rest API ====== | + | ====== REST API ====== |
===== Introduction ===== | ===== Introduction ===== | ||
原本就有接觸過Facebook Graph API,因工作關係接觸到Rest,所以學習起來比較不陌生。因為網路資料相當豐富,我只記錄些自己容易忘記的部分。 | 原本就有接觸過Facebook Graph API,因工作關係接觸到Rest,所以學習起來比較不陌生。因為網路資料相當豐富,我只記錄些自己容易忘記的部分。 | ||
行 6: | 行 6: | ||
* [[java:web:restapi:X-HTTP-Method-Override Filter|Incorrect response(401) when using X-HTTP-Method-Override]] | * [[java:web:restapi:X-HTTP-Method-Override Filter|Incorrect response(401) when using X-HTTP-Method-Override]] | ||
* [[java:web:restapi:rpc-style_vs_rest|RPC-Style API VS REST API]] | * [[java:web:restapi:rpc-style_vs_rest|RPC-Style API VS REST API]] | ||
- | * [[java:web:restapi:http_method_cant_make_sense|Http Method無法表達出某些動作]] (施工中) | + | * [[java:web:restapi:http_method_cant_make_sense|Http Method無法表達出某些動作]] |
+ | * [[java:web:restapi:response_code|Response Code]] | ||
+ | * [[java:web:restapi:url|URL相關設計]] | ||
===== Firewall issue of HTTP Delete & Put operations ===== | ===== Firewall issue of HTTP Delete & Put operations ===== | ||
HTTP Delete與Put操作可能會被防火牆阻擋,經過Study有三種替代方案。 | HTTP Delete與Put操作可能會被防火牆阻擋,經過Study有三種替代方案。 | ||
行 13: | 行 15: | ||
- Request with Header X-HTTP-Method-Override=DELETE: 透過Header置換操作。(參考[[https://www.isostech.com/blogs/web-application-development/put-delete-requests-yui3-spring-mvc/|link]]) | - Request with Header X-HTTP-Method-Override=DELETE: 透過Header置換操作。(參考[[https://www.isostech.com/blogs/web-application-development/put-delete-requests-yui3-spring-mvc/|link]]) | ||
個人覺得第三種做法比較正規些,目前知道[[https://www.firebase.com/docs/rest/api/|firebase]]、[[http://docs.oracle.com/cloud/latest/marketingcs_gs/OMCAB/Developers/GettingStarted/API%20requests/http-request-headers.htm|oracle的OMCAB]]與[[https://www-01.ibm.com/support/knowledgecenter/SSFPJS_8.5.6/com.ibm.wbpm.ref.doc/rest/repository/index.htm|IBM Business Process Manager]]都用這做法。 | 個人覺得第三種做法比較正規些,目前知道[[https://www.firebase.com/docs/rest/api/|firebase]]、[[http://docs.oracle.com/cloud/latest/marketingcs_gs/OMCAB/Developers/GettingStarted/API%20requests/http-request-headers.htm|oracle的OMCAB]]與[[https://www-01.ibm.com/support/knowledgecenter/SSFPJS_8.5.6/com.ibm.wbpm.ref.doc/rest/repository/index.htm|IBM Business Process Manager]]都用這做法。 | ||
- | ===== Terms ===== | ||
- | ==== Hypermedia Control ==== | ||
- | Richardson Maturity Model所定義的等級3。主要有兩個好處: | ||
- | - 如果使用者是根據Hypermedia link做操作,Server是可以自行修改URI而不需要通知使用者。 | ||
- | - 使用者可以根據Hypermedia link知道: 接下來可以做什麼。 | ||
- | 而Richardson提到,Hypermedia link該怎麼呈現並沒有一定規範,他是使用rel描述關係,uri描述連結的方式: | ||
- | <code html> | ||
- | <link rel = "/linkrels/appointment/cancel" | ||
- | uri = "/slots/1234/appointment"/> | ||
- | <link rel = "/linkrels/appointment/addTest" | ||
- | uri = "/slots/1234/appointment/tests"/> | ||
- | <link rel = "self" | ||
- | uri = "/slots/1234/appointment"/> | ||
- | </code> | ||
- | 以Richardson的方法而言,他的rel也表達了對應動作。換成PayPal REST Payment API的例子: | ||
- | <code cpp> | ||
- | "links" : [{ | ||
- | "href" : "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2XR800907F429382MKEBWOSA", | ||
- | "rel" : "self", | ||
- | "method" : "GET" | ||
- | }, { | ||
- | "href" : "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2XR800907F429382MKEBWOSA/execute", | ||
- | "rel" : "update", | ||
- | "method" : "POST" | ||
- | } | ||
- | ] | ||
- | </code> | ||
- | PayPal則是多了method去表達對應的HTTP request。 | ||
===== Resource ===== | ===== Resource ===== | ||
行 56: | 行 30: | ||
* [[http://stackoverflow.com/questions/2427518/which-http-redirect-status-code-is-best-for-this-rest-api-scenario|Which HTTP redirect status code is best for this REST API scenario?]] | * [[http://stackoverflow.com/questions/2427518/which-http-redirect-status-code-is-best-for-this-rest-api-scenario|Which HTTP redirect status code is best for this REST API scenario?]] | ||
* [[http://www.slideshare.net/ewolff/rest-vs-messaging-for-microservices|REST VS JMS of microservices]] | * [[http://www.slideshare.net/ewolff/rest-vs-messaging-for-microservices|REST VS JMS of microservices]] | ||
- | * [[http://tatiyants.com/using-oauth-to-protect-internal-rest-api/|using-oauth-to-protect-internal-rest-api]] studying.. | ||
* [[https://community.alfresco.com/docs/DOC-5717-32-rest-api-group-service#w_rootgroupscollection|Alfresco - Group設計]] | * [[https://community.alfresco.com/docs/DOC-5717-32-rest-api-group-service#w_rootgroupscollection|Alfresco - Group設計]] | ||
* [[https://stackoverflow.com/questions/207477/restful-url-design-for-search|Design for search]] | * [[https://stackoverflow.com/questions/207477/restful-url-design-for-search|Design for search]] | ||
行 73: | 行 46: | ||
* [[https://blog.akana.com/hypermedia-apis/|The Movement Towards Hypermedia APIs – Is it Happening?]] | * [[https://blog.akana.com/hypermedia-apis/|The Movement Towards Hypermedia APIs – Is it Happening?]] | ||
* [[https://www.vegaitsourcing.rs/media-center/blog/2015/04/hypermedia-driven-restful-web-apis/|Hypermedia-driven RESTful web APIs]] | * [[https://www.vegaitsourcing.rs/media-center/blog/2015/04/hypermedia-driven-restful-web-apis/|Hypermedia-driven RESTful web APIs]] | ||
+ | * [[https://stackoverflow.com/questions/35700344/rest-api-and-ddd?fbclid=IwAR2J_PFxqgMfDEBh3rFbSY-2cOvhoQhpw7MTynLoa2fZqHeuy-4lcK6PnkE|Rest API and DDD]] | ||
+ | * [[https://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api|Best Practices for Designing a Pragmatic RESTful API]] | ||
==== Basic ==== | ==== Basic ==== | ||
* [[https://ihower.tw/blog/archives/6483|HTTP Verbs: 談 POST, PUT 和 PATCH 的應用]] | * [[https://ihower.tw/blog/archives/6483|HTTP Verbs: 談 POST, PUT 和 PATCH 的應用]] | ||
* [[https://stackoverflow.com/questions/3825990/http-response-code-for-post-when-resource-already-exists|post with duplicate resource]] | * [[https://stackoverflow.com/questions/3825990/http-response-code-for-post-when-resource-already-exists|post with duplicate resource]] | ||
* [[https://www.infoworld.com/article/3206264/application-development/how-to-perform-partial-updates-to-rest-web-api-resources.html|How to do partial updates to REST API resources?]] | * [[https://www.infoworld.com/article/3206264/application-development/how-to-perform-partial-updates-to-rest-web-api-resources.html|How to do partial updates to REST API resources?]] | ||
+ | |||
+ | ==== Security ==== | ||
+ | * [[http://tatiyants.com/using-oauth-to-protect-internal-rest-api/|using-oauth-to-protect-internal-rest-api]] studying.. | ||
+ | * [[https://nordicapis.com/3-common-methods-api-authentication-explained/|3 Common Methods of API Authentication Explained]] | ||
+ | * [[https://www.itread01.com/p/12089.html|OpenID Connect 協議入門指南]] | ||
+ | * [[https://sysmgt.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.lxca_restapis.doc%2Frest_apis_reference.html|修改密碼的REST API]] | ||
+ | ==== URI ==== | ||
+ | * [[http://blog.restcase.com/7-rules-for-rest-api-uri-design/|7 Rules for REST API URI Design]] | ||
+ | |||
==== Transaction ==== | ==== Transaction ==== | ||
* [[http://www.slideshare.net/cesare.pautasso/atomic-transactions-for-the-rest-of-us|Atomic Transactions for the REST of us]] | * [[http://www.slideshare.net/cesare.pautasso/atomic-transactions-for-the-rest-of-us|Atomic Transactions for the REST of us]] |