summer-of-code-2024

Frontend Development : Week 2

As discussed in the last week’s session, this week, we will have a short introduction to what is API (for a detailed approach on how to make one, follow backend’s materials) and how we use API to set up communication between server and client, in order to retrive, authenticate and store information.

This week is all about JS (and ofc, HTML, CSS and Bootstrap!) and getting comfortable with it, before we introduce ReactJS in the next week!

Learning Tasks

Task 1 - Fetch APIs

Now that we have the login and sign up pages ready (hopefully, tailored to send info regarding admin or cashier portal login),we will now use Fetch APIs to interact with the given API to autheticate information sent from client. The Fetch method is a method provided by the Fetch API that is built into the browser. It is used to get access to data through the use of the HTTP protocol. It simplifies fetching resources, handling responses, and managing errors.

    const requestUrl = "url of whatever you want to make a request to";
    fetch(requestUrl)
    .then(response => response.json())
    .then(data => {
    // do something with the data the API has returned
    })

This is the general syntax of how a fetch request is made.

Task 2 - Bootstrap

Add the following lines to your code.

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Dashboard</title>
  <link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
    rel="stylesheet"
    integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"
    crossorigin="anonymous"
  />
</head>

<body>
  <script
    src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
    crossorigin="anonymous"
  ></script>
</body>

API Documentation

Authentication API

Endpoint: http://167.71.236.10/api/login/

Method: POST

Description: Authenticate user credentials and retrieves token.

Request Body:

{
  "username": "admin",
  "password": "admin@dsoc24"
}

Handle this token properly in your frontend as it would be required while making other api calls.

Bonus Tasks

Practice of using HTML, Bootstrap and this time, using Javascript to add more functionality and interactivity to the portal!