Skip to content

aztack/todolist-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Todo list API build with Golang and Sqlite3

Build

go build

Run

./todolist-api

API

Struct

type Todo struct {
  ID      uint   `json:"id"`
  Done    bool   `json:"done"`
	Content string `json:"content"`
}

Access with Axios and jQuery

// Axios
axios.post('http://localhost:8888/todo/create', {content:"buy a book"}).then(resp => console.log(resp.data));
axios.get('http://localhost:8888/todos').then(resp => console.log(resp.data));

// jQuery
$.ajax({
  url: 'http://localhost:8888/todo/create',
  method: 'POST',
  contentType: 'application/json',
  data: JSON.stringify({content:"buy a book"}),
  success: function (todo) {
    console.log(todo)
  },
  error: function (xhr, status) {
    console.error("error");
  }
});

$.ajax({
  url: "http://localhost:8888/todos",
  type: "GET",
  crossDomain: true,
  dataType: "json",
  success: function (todos) {
    console.log(todos)
  },
  error: function (xhr, status) {
    console.error("error");
  }
});

License

MIT