# RESTful API实践
# Methods方法
GET /articles/1 #读取,返回200
PUT /articles/1 #编辑(或路径),返回200
DELETE /articles/1 #删除,返回200
POST /articles #创建,返回201
GET /articles #清单,传回200
1
2
3
4
5
2
3
4
5
# Status codes(状态码)
200 OK #成功获取,修补(返回JSON对象)
201 Created #成功发布(返回JSON对象)
202 Accepted #成功发布,删除,路径-异步
204 No content #成功删除
206 Partial content #成功获取-异步
401 Unauthorized #未认证
403 Forbidden #已验证,但没有权限
422 Unprocessable entity #验证方式
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# Errors
HTTP/1.1 401 Unauthorized
Content-Type: application/json
{
'id': 'auth_failed',
'message': "You're not logged in."
}
1
2
3
4
5
6
2
3
4
5
6
# request.getParameter()
获取参数为null
和""
空字符串的区别
# ""
空字符串
当url
里有name
属性,但是没有值的时候后台用request.getParameter("name")
获取的是空字符串""
# null
当url
里没有name
属性,request.getParameter("name")
获取的值是null
# 提取双引号中间的值(regex
)
String str1 = "\"小明\"";
String ps = "(?<=\").*?(?=\")";
Pattern p = Pattern.compile(ps);
Matcher m = p.matcher(str1);
while(m.find()){
System.out.println(m.group());
}
// output: 小明
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9