Skip to content

doublemc/ToDoWebApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToDoWebApp is a REST API that lets you add, manage and complete your own ToDos.

It was created as a learning experience for Spring and Hibernate. It's a backend app that should be 'consumed' by a frontend REST client eg. Angular JS. It supports basic CRUD operations via HTTP requests. Stack used:

  • Spring Boot
  • Spring Security for Basic Auth implementation and hashing passwords
  • Hibernate for ORM
  • H2 in-memory database to store registered users and their ToDos
  • JUnit & Mockito for unit and integration testing

Usage example:

POST @ localhost:8080/users with body:

{
	"username":"doublemc",
	"password":"password",
	"email":"doublemc@example.com"
}

registers new user and responses with:

HTTP.Status: 201 Created 
{
  "status": "User created."
}

Then you can use POST @ localhost:8080/todos using JSON again to create a new ToDo:

{
	"title":"default",
	"dueDate": [
		2000,
		10,
		10
	]
}

...and the server response is: (id is autogenerated by database)

HTTP.Status 201 Created
{
  "id": 1, 
  "title": "default",
  "completed": false,
  "dueDate": [
    2000,
    10,
    10
  ]
}

After creating a ToDo you can view all your ToDos by using GET @ localhost:8080/todos :

[
  {
    "id": 1,
    "title": "default",
    "completed": false,
    "dueDate": [
      2000,
      10,
      10
    ]
  }
]

If you completed a ToDo just use PATCH @ localhost:8080/todos/{id}/complete (without any request body) and you will get HTTP.Status 200 OK.

Updating a ToDo can be achieved by using PUT @ localhost:8080/todos/{id} with the same JSON structure as in creating a new ToDo.

Removing a ToDo is easily achievable with DELETE @ localhost:8080/todos/{id} and server responses with HTTP.Status 204 No Content

If you don't like my API you can always delete your own account by using DELETE @ localhost:8080/users and it will delete from database currently logged in user (so called Principal in Spring Security).

All of the above requests (apart from creating a new user) require you to use Basic Authentication - provide username and password (that you used for account creation) to access those functionalities. If you don't use correct password or username is not found in the database you will get:

{
  "timestamp": 1487444087657,
  "status": 401,
  "error": "Unauthorized",
  "message": "Bad credentials",
  "path": "/todos/1"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages