Skip to content

JesusRomanDev/Fullstack-RestAPI-CSV-Viewer-file-w-TypeScipt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Full Stack REST API - SPA - CSV File Viewer - Monorepo w NPM Workspaces

Portada Web Application that allow users to upload CSV file with pre formated data and able to show those data as cards in the frontend, additionally able to filter in a search bar. This leads to a full stack project where the best practices in the RESTful API were showed.

Built with

Static Badge
Static Badge
Static Badge
Static Badge
Static Badge
Static Badge
Static Badge
Static Badge

Overview

Frontend

-SPA
-NO Magic Strings to avoid make it more error-prone, and difficult to maintain as it evolves over time.

-Search bar to find/filter the results we want(id, name, email, etc...).

-Sooner package for toast component to make it friendly the errors.
-window.history.pushState() used to modify the search history without reaload the browser and make it more friendly and efficient to the user.

Backend

-RESTful API.
-Best practices for the API, accept (in this case since it's a file first we have to check the buffer then convert csv to json) and response with JSON, naming conventions, allowing filtering, handle errors gracefully and return standard error codes.

-Multer middleware for handling multipart/form-data, for our csv file.
-Part of Multer middleware, convert csv to json function to be able to recieve JSON and response with so to get stick to good practices.

Multer

As we are going to upload files, Multer was the best option for handling multipart/form-data, the process was first to add the file into the input button, then with the event.target.files assign it into a variable used by the hook "useState", then pass it to a function and create a new formData, very important is to NOT ADD ANY HEADERS, since we need to let the browser to add the apropiate boundaries.

Then make the call to the appropiate endpoint in the RESTful API and the backend will accept the multipart/form-data, since we want to store it into the memory i used const storage = multer.memoryStorage(); const upload = multer({storage: storage}); in order to have access to the buffer and turn it into a string (rawCSV), then use the function CSVtoJson and finally adding into memory and respond with JSON.

UI States

Looking at our CSV file

Before selecting our file let's see how it looks

Now let's select our file

After selecting a file

Now we are ready to hit the upload button and show the result but first...

Uploading the file

The uploading state is now on scene.

Showing the Cards with the result of the CSV

All the results are listed as a card, each inside a div with all the information.

Toasts

File uploaded successfully

Error

Filtering the data and window.history.pushState()

Filter by Number

Filter by Name

Filter by Department Area

How pushState handles the searches

About

Typescript Fullstack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published