Practical work 3

https://github.com/heig-vd-dai-course

Web · PDF

L. Delafontaine and H. Louis, with the help of GitHub Copilot.

This work is licensed under the CC BY-SA 4.0 license.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Objectives

  • Acquire a virtual machine from a cloud provider
  • Access the virtual machine (SSH)
  • Install Docker and Docker Compose
  • Develop a simple CRUD API
  • Deploy the applications (reverse proxy + CRUD API)
  • Access the applications from a (free) domain name
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0
  • The CRUD API manages resources. You can choose what the CRUD API does/manages:
    • Music
    • Books
    • Video games
    • A todo/groceries list
    • ...

The CRUD API must be accessible from the internet.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Demo

The API for the demonstration is accessible at
https://heig-vd-dai-course.duckdns.org.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Locally - Compile the project:

./mvnw clean package

Locally - Build the Docker image with Docker Compose:

docker build -t <docker tag> .

Locally - Publish the Docker image to the container registry:

docker push <docker tag>
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

On the server - Pull the Docker image from the container registry:

docker compose pull

On the server - Start Traefik (the reverse proxy):

docker compose -f traefik/docker-compose.yaml up -d

On the server - Start the CRUD API:

docker compose -f api/docker-compose.yaml up -d
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Create a few drinks:

# Hot wine
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"name":"Hot wine","description":"Hot wine with spices","price":3.0}' \
  https://heig-vd-dai-course.duckdns.org/drinks

# Christmas tea
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"name":"Christmas tea","description":"Warm tea","price":2.0}' \
  https://heig-vd-dai-course.duckdns.org/drinks
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Get the list of drinks:

curl https://heig-vd-dai-course.duckdns.org/drinks

Output:

[
  {
    "id": 1,
    "name": "Hot wine",
    "description": "Hot wine with spices",
    "price": 3.0
  }
  // All the other drinks
]
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Filter the drinks with a price equal to 2.0 CHF:

curl https://heig-vd-dai-course.duckdns.org/drinks?price=2.0

Output:

[
  {
    "id": 2,
    "name": "Christmas tea",
    "description": "Warm tea",
    "price": 2.0
  }
]
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Get a specific drink:

curl https://heig-vd-dai-course.duckdns.org/drinks/1

Output:

{
  "id": 1,
  "name": "Hot wine",
  "description": "Hot wine with spices",
  "price": 3.0
}
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Update a drink:

curl -X PUT \
  -H "Content-Type: application/json" \
  -d '{"name":"Hot wine","description":"Nice hot wine","price":3.0}' \
  https://heig-vd-dai-course.duckdns.org/drinks/1

Output:

{
  "id": 1,
  "name": "Hot wine",
  "description": "Nice hot wine",
  "price": 3.0
}
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Delete a drink:

curl -X DELETE -i https://heig-vd-dai-course.duckdns.org/drinks/1

Output:

HTTP/2 204
content-type: text/plain
date: Sat, 16 Dec 2023 13:31:56 GMT

No content as we return a 204 (No Content) status code!

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Adding another drink with the same name:

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"name":"Christmas tea","description":"Another tea","price":2.0}' \
  https://heig-vd-dai-course.duckdns.org/drinks

Output:

Conflict

Leads to a 409 (Conflict) status code as we want to keep the names unique.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Group composition

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Group composition

  • 2 or 3 students per group
  • Create a GitHub Discussion to:
    • Announce your group members
    • Announce your idea (even a draft is fine)
  • Do it as soon as possible before next week!
    • This helps us to plan the presentations
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Idea validation

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Idea validation

  • You must state your idea on your GitHub Discussion
  • We might ask you to change your idea if it is too simple or too complex
  • We will help you to find a good idea if needed
  • Do it as soon as possible before next week!
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Grading criteria

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Grading criteria

You can find all the grading criteria in the course material:

  • 0 point - The work is insufficient
  • 0.1 point - The work is done
  • 0.2 point - The work is well done (without the need of being perfect)

Maximum grade: 25 points * 0.2 + 1 = 6

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Constraints

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Constraints

  • The application must be written in Java, compatible with Java 21
  • The application must be built using Maven with the maven-shade-plugin plugin
  • The application must use the Javalin dependency
  • You can only use the Java classes seen in the course
  • Your application must be slightly more complex and slightly different than the examples presented during the course (we emphasize the word slightly, no need to shoot for the moon!)
  • The web application can only use the HTTP/HTTPS protocols
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Tips

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Tips

You are allowed to reuse your Bases de données relationnelles (BDR) project for this practical work.

You can decide to merge the two projects into one if you want or keep the idea and implement it in a different way (in memory for example, as you will see in the course materials).

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Submission

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Submission

Your work is due as follow:

  • DAI-TIC-B (Monday mornings): 19.01.2025 23:59
  • DAI-TIC-C (Friday mornings): 23.01.2025 23:59

Update the GitHub Discussion with the link to your repository as mentioned in the course material.

If you do not submit your work on time and/or correctly, you will be penalized (-1 point on the final grade for each day of delay).

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Presentations

More details for this section in the course material.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Presentations

The practical work presentations will take place in TBD on:

  • DAI-TIC-B (Monday mornings): 20.01.2025
  • DAI-TIC-C (Friday mornings): 24.01.2025

We only have TBD minutes per group. You decide what you want to show us and how you want to present it. Come 5 minutes before your time slot with your computer. You will have access to a beamer.

Please state your group on GitHub Discussions before next week.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Grades and feedback

Grades will be entered into GAPS, followed by an email with the feedback.

The evaluation will use exactly the same grading grid as shown in the course material.

Each criterion will be accompanied by a comment explaining the points obtained, a general comment on your work and the final grade.

If you have any questions about the evaluation, you can contact us!

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Questions

Do you have any questions?

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Find the practical work

You can find the practical work for this part on GitHub.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Finished? Was it easy? Was it hard?

Can you let us know what was easy and what was difficult for you during this practical work?

This will help us to improve the course and adapt the content to your needs. If we notice some difficulties, we will come back to you to help you.

➡️ GitHub Discussions

You can use reactions to express your opinion on a comment!

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Sources

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0