From d4743fb10d441470f8ad6933e75baaeed6fe15fc Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 10 Jul 2013 22:06:28 +0800 Subject: [PATCH] Sync documentation of English with Chinese version --- docs/en/API.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 docs/en/API.md diff --git a/docs/en/API.md b/docs/en/API.md new file mode 100644 index 00000000..1409d882 --- /dev/null +++ b/docs/en/API.md @@ -0,0 +1,102 @@ +# Getting start with API application development +Go is very good for developing API applications which I think is the biggest strength compare to other dynamic languages. Beego provides powerful and quick setup tool for developing API applications, which gives you more focus on business logic. + + +## Quick setup +bee can setup a API application very quick by executing commands under any `$GOPATH/src`. + +`bee api beeapi` + +## Application directory structure + + ``` +├── conf +│ └── app.conf +├── controllers +│ └── default.go +├── models +│ └── object.go +└── main.go +``` + +## Source code explanation + +- app.conf has following configuration options for your API applications: + + - autorender = false // Disable auto-render since API applications don't need. + - copyrequestbody = true // RESTFul applications sends raw body instead of form, so we need to read body specifically. + +- main.go is for registering routers of RESTFul. + + beego.RESTRouter("/object", &controllers.ObejctController{}) + +Match rules as follows: + + + + + + + + + + + + + + + + + + + + +
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
+ +- ObejctController implemented corresponding methods: + + type ObejctController struct { + beego.Controller + } + + func (this *ObejctController) Post(){ + + } + + func (this *ObejctController) Get(){ + + } + + func (this *ObejctController) Put(){ + + } + + func (this *ObejctController) Delete(){ + + } + +- models implemented corresponding object operation for adding, deleting, updating and getting. + +## Test + +- Add a new object: + + curl -X POST -d '{"Score":1337,"PlayerName":"Sean Plott"}' http://127.0.0.1:8080/object + + Returns a corresponding objectID:astaxie1373349756660423900 + +- Query a object: + + `curl -X GET http://127.0.0.1:8080/object/astaxie1373349756660423900` + +- Query all objects: + + `curl -X GET http://127.0.0.1:8080/object` + +- Update a object: + + `curl -X PUT -d '{"Score":10000}'http://127.0.0.1:8080/object/astaxie1373349756660423900` + +- Delete a object: + + `curl -X DELETE http://127.0.0.1:8080/object/astaxie1373349756660423900`