一,效果
二,后端 使用go 开发,采用gin框架。主要接口如下:
v1.GET("todo", Controllers.GetTodos)
v1.POST("todo", Controllers.CreateATodo)
v1.GET("todo/:id", Controllers.GetATodo)
v1.PUT("todo/:id", Controllers.UpdateATodo)
v1.DELETE("todo/:id", Controllers.DeleteATodo)
参考:https://medium.com/@_ektagarg/golang-a-todo-app-using-gin-980ebb7853c8
三,前端采用 纯QML 开发,网络部分,利用js 编写
function request(verb,endpoint,obj,cb) {
print('request: '+verb+' '+endpoint)
var xhr = new XMLHttpRequest()
xhr.onreadystatechange=function(){
if(xhr.readyState===XMLHttpRequest.DONE){
if(cb){
var res = JSON.parse(xhr.responseText.toString())
cb(res)
}
}
}
xhr.open(verb,endpoint)
xhr.setRequestHeader('Content-Type','application/json')
xhr.setRequestHeader('Accept','application/json')
var data = obj?JSON.stringify(obj):''
xhr.send(data)
}
function get_todos(cb){
request('GET',"http://xxxx:8080/v1/todo",null,cb)
}
function add_todo(entry,cb){
request('POST',"http://xxxx:8080/v1/todo",entry,cb)
}
function delete_todo(index,cb){
request('DELETE',"http://xxxx:8080/v1/todo/"+index,null,cb)
}
function update_todo(index,entry,cb){
request('PUT',"http://xxxx:8080/v1/todo/"+index,entry,cb)
}
参考:enginio\quick 的官方例子