URL HTTP Verb Functionality
/object POST Creating Objects
/object/objectId GET Retrieving Objects
/object/objectId PUT Updating Objects
/object GET Queries
/object/objectId DELETE Deleting Objects
type ObejctController struct {
beego.Controller
}
func (this *ObejctController) Post(){
}
func (this *ObejctController) Get(){
}
func (this *ObejctController) Put(){
}
func (this *ObejctController) Delete(){
}
测试
添加一个对象:
curl -X POST -d '{"Score":1337,"PlayerName":"Sean Plott"}' http://127.0.0.1:8080/object
返回一个相应的objectID:astaxie1373349756660423900
查询一个对象
curl -X GET http://127.0.0.1:8080/object/astaxie1373349756660423900
查询全部的对象
curl -X GET http://127.0.0.1:8080/object
更新一个对象
curl -X PUT -d '{"Score":10000}'http://127.0.0.1:8080/object/astaxie1373349756660423900
删除一个对象
curl -X DELETE http://127.0.0.1:8080/object/astaxie1373349756660423900
本文介绍了一个简单的RESTful API实现案例,包括对象的创建、查询、更新及删除等操作,并提供了具体的curl命令示例。
930

被折叠的 条评论
为什么被折叠?



