boalbert / student-management-system

Laboration Komplex Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JAVA EE / JAX-RS - Labb

Komplex Java - JU2020

Endpoints

  • GET - ONE
/api/v1/students/{id}

// Response Code: 200 OK
  • GET - ALL
/api/v1/students/

// Response Code: 200 OK
  • GET - BY LASTNAME
/api/v1/students/search?lastName={lastName}

// Example, Query Parameter
/api/v1/students/search?lastName=Persson

// Response Code: 200 OK
  • POST
/api/v1/students

// Body
{
	"firstName" : "Sara", 
	"lastName" : "Persson", 
	"email" : "sarap@email.com",
	"phoneNumber" : "073548824"
}

// Response Code: 201 Created
// Header - Location: .../student-management-system/api/v1/students/1
  • PUT
/api/v1/students/{id}

// Body
{
	"firstName" : "Sara",
	"lastName" : "Andersson",
	"email" : "saraandersson@email.com",
	"phoneNumber" : "073548824"
}

// Response Code: 200 OK / 201 Created
// 201 Created: 
	// Header - Location: .../student-management-system/api/v1/students/1
  • PATCH
/api/v1/students/{id}

// Body
{
	"email" : "andersson@email.com"
}

// Response Code: 200 OK 
  • DELETE
/api/v1/students/{id}

// Response Code: 204 No content

Constraints

@Size(min = 2, message = "Min. 2 characters")
@NotEmpty(message = "Must not be empty")
private String firstName;

@Size(min = 2, message = "Min. 2 characters")
@NotEmpty(message = "Must not be empty")
private String lastName;

@Email(regexp = ".+@.+\\..+", message = "Not a valid email adress.")
@NotEmpty(message = "Must not be empty")
private String email;

Exceptions

  • StudentNotFoundException
    • GET, PATCH
// Response Code: 404 Not Found
{
  "error message": "Student not found.",
  "student id": 99
}
  • ConstraintViolationException
    • POST, PUT, PATCH
// Response Code: 400 Bad Request
[
  {
    "error message": "Must not be empty",
    "property": "firstName"
  },
  {
    "error message": "Not a valid email adress.",
    "property": "email"
  },
  {
    "error message": "Must be between 2 - 50 characters",
    "property": "lastName"
  },
  {
    "error message": "Must be between 2 - 50 characters",
    "property": "firstName"
  }
]

About

Laboration Komplex Java


Languages

Language:Java 100.0%