当前位置:网站首页>Understand restful architecture
Understand restful architecture
2022-06-21 12:10:00 【attempt_ to_ do】
1.REST
RESTful, It is the most popular Internet software architecture at present . Because it's structured 、 Meet the standard 、 Easy to understand 、 Easy to expand , So more and more websites are using .
1.1. What is? REST
REST Refers to a set of architectural constraints and principles . An application or design that satisfies these constraints and principles is RESTful Of .
REST A few concepts :
- resources REST yes “ Represent layer state transformation ”.“ The presentation layer ” refer to “ resources ” The performance layer of ;
- The presentation layer : A resource is a specific entity information , There can be many ways to show , Showing entities is the presentation layer ;
- State transformation : Visit a website , It represents an interactive process between the client and the server , This process involves the transformation of data and state ;
2.RESTful framework
RESTful The architecture needs to meet the following conditions :
- Every URL Represents a resource ;
- Between client and server , A layer of expression that conveys this resource ;
- Client pass HTTP Verb , Operate the server-side resources , Realization ” Expression layer transformation “;
Web The application should satisfy REST The most important principle is : The interaction between client and server is stateless between requests , That is, every request from the client to the server must contain the necessary information to understand the request . If the server restarts at any point in time between requests , The client will not be notified . In addition, this request can be answered by any available server , It's perfect for environments like cloud computing . Because it's stateless , So clients can cache data to improve performance . Another important thing REST The principle is system layering , This means that the component cannot understand any component other than the hierarchy it interacts with directly . By limiting system knowledge to a single layer , Can limit the complexity of the entire system , This promotes the independence of the bottom layer .
Realization RESTful Application design of
package main
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}
func getuser(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
uid := ps.ByName("uid")
fmt.Fprintf(w, "you are get user %s", uid)
}
func modifyuser(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
uid := ps.ByName("uid")
fmt.Fprintf(w, "you are modify user %s", uid)
}
func deleteuser(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
uid := ps.ByName("uid")
fmt.Fprintf(w, "you are delete user %s", uid)
}
func adduser(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// uid := r.FormValue("uid")
uid := ps.ByName("uid")
fmt.Fprintf(w, "you are add user %s", uid)
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name", Hello)
router.GET("/user/:uid", getuser)
router.POST("/adduser/:uid", adduser)
router.DELETE("/deluser/:uid", deleteuser)
router.PUT("/moduser/:uid", modifyuser)
log.Fatal(http.ListenAndServe(":8080", router))
}
summary
REST It's an architectural style , Absorbed WWW Experience of success : No state , Resource centric , make the best of HTTP The protocol and URI agreement , Provide a unified interface definition , Make it a design Web The service method has become popular . In a sense , By emphasizing URI and HTTP And so on Internet standard ,REST Before the era of large application servers Web The return of ways . at present Go about REST It's still very simple , By implementing custom routing rules , We can do it for different method Make a difference handle, That's it REST The architecture of .
边栏推荐
猜你喜欢

记一次Vmware虚拟机升级GLIBC导致系统瘫痪的恢复解决方法

Summary of UART problems in stm32cubemx

harmonyos培训一
![[cloud native | Devops] Jenkins installation and actual combat (II)](/img/1f/68ec217a920fb7c737227137e3243c.png)
[cloud native | Devops] Jenkins installation and actual combat (II)

SDCC编译器 + VSCode开发 8位微控制器

Huawei cloud releases desktop ide codearts

对文件夹下所有的文件一键改名

External attention tensorflow (under update)

One's deceased father grind politics English average cent furnace! What is your current level?

RPC(远程过程调用协议)
随机推荐
Nanjing University static program analyses -- Introduction learning notes
Customization of power aging test system | overview of charging pile automatic test system nsat-8000
Typescript variable declaration - type assertion
MySQL 5.6.49 enterprise version setting password complexity policy
[deep learning] use deep learning to monitor your girlfriend's wechat chat?
100w的数据表比1000w的数据表查询更快吗?
What are the precautions for PCB design?
STM32开发之 VS Code + gcc环境编译
Use praise to improve performance 
Typera free version, without cracking, can be installed and used directly
Related codes of findpanel
Illustrated with pictures and texts -- wechat applet to obtain the user's geographic location information and call Tencent map API to obtain the user's specific location
巨头局终战:即时零售
南京大学 静态软件分析(static program analyzes)-- Intermediate Representation 学习笔记
HMS core machine learning service ID card identification function to achieve efficient information entry
矩形覆盖面积
中信建投券商是跟启牛学堂存在什么关系?开券商账户安全吗
一键打新债到底安不安全呀?是不是靠谱的?
浅论OCA\UV-OCA LOCA\SLOCA 四种全贴合工艺
Musk's "good friend" impacts the largest IPO of Hong Kong stocks in 2022