MVC Architecture Demo App
import QtQuick 2.0
import Felgo 4.0
Item {
readonly property bool busy: HttpNetworkActivityIndicator.enabled
property int maxRequestTimeout: 5000
Component.onCompleted: {
HttpNetworkActivityIndicator.setActivationDelay(0)
}
QtObject {
id: _
property string todoUrl: "https://jsonplaceholder.typicode.com/todos"
function fetch(url, success, error) {
HttpRequest.get(url)
.timeout(maxRequestTimeout)
.then(function(res) { success(res.body) })
.catch(function(err) { error(err) });
}
function post(url, data, success, error) {
HttpRequest.post(url)
.timeout(maxRequestTimeout)
.set('Content-Type', 'application/json')
.send(data)
.then(function(res) { success(res.body) })
.catch(function(err) { error(err) });
}
}
function getTodos(success, error) {
_.fetch(_.todoUrl, success, error)
}
function getTodoById(id, success, error) {
_.fetch(_.todoUrl+"/"+id, success, error)
}
function addTodo(todo, success, error) {