Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dreyydk/carmanager-api
A Rest API capable of creating and communicating with a database containing information about cars and their brands.
https://github.com/dreyydk/carmanager-api
api-rest express git nodejs npm postgresql postman sequelize
Last synced: 3 days ago
JSON representation
A Rest API capable of creating and communicating with a database containing information about cars and their brands.
- Host: GitHub
- URL: https://github.com/dreyydk/carmanager-api
- Owner: dreyydk
- Created: 2024-07-17T13:35:12.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-08-07T13:39:36.000Z (3 months ago)
- Last Synced: 2024-08-07T16:31:23.153Z (3 months ago)
- Topics: api-rest, express, git, nodejs, npm, postgresql, postman, sequelize
- Language: JavaScript
- Homepage:
- Size: 4.07 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
CarManager API
A Rest API capable of creating and communicating with a database containing information about cars and their brands. It can be very useful for developers aiming to create an application that involves this niche, such as a dealership website.
## Features
- **Database creation and management:** By entering a few commands in the terminal, the API can create and manage a database with ready-made tables for cars and brands.
- **CRUD operations:** Through ready-made requests located in the "routes" and "controllers" files, the API can perform CRUD operations (create, read, update and delete) directly on the database it creates.## Benefits
- **Easily customizable:** If the developer wants to add or remove a column from any table, this can be easily done by editing the "migrations" and "models" files. _Note: These changes must be made before migrating the tables to the database, otherwise it will be necessary to perform another migrate._
- **Highly flexible:** This API can be used for practically any web application that uses PostgreSQL as a management system.## Technologies
## Starter guide
### Relevant information before using the API.
- It is **highly recommended** to use PostgreSQL as a management system, as the entire API was developed with it in mind, and it is not possible to say with 100% certainty that it will work correctly in another system. If you don't have it installed, you can check it by clicking on this link.
- As the API was developed in Node.js, you must have it installed on your machine to run the application. If you don't have it yet, please install it using this link.
- Most of the necessary dependencies are already pre-installed, with the exception of **sequelize-cli**, which is necessary to run the API command lines in the terminal. If you don't have this dependency installed globally, this can be easily done by typing `npm install -g sequelize-cli` in your terminal.
- By default, the API works with the JSON format for data, but developers are free to change this according to their preferences.### Step 1: Preparing the environment.
- Clone the repository to your machine.
- Locate the "config.js" file in the "configs" folder and modify it according to your PostgreSQL environment.
- Open your terminal and run `sequelize db:create` to create the database.
- Still in the terminal, run `sequelize db:migrate` to send the migrations (tables) to the database.
- With this, you should have a structured database with car and brand tables, which you can check by accessing your pgAdmin.### Step 2: Doing the first tests.
- With the database ready, it is now possible to execute test requests. A personal recommendation for running these tests is Postman, a very good free tool, you can check it out by clicking this link. _Note: Can also be used as a VS Code extension._
- To start, it is necessary to run the "server.js" file, which represents the application server, this can be done through the `node src/server.js` command in the terminal, but another personal recommendation is to use the nodemon library (which is already pre-installed in the API), this can be done with the command `npx nodemon src/server.js`, also in the terminal.### POST Requests.
The API uses the POST method to create brands and cars in the database. Brands must be created before cars, as they have an identifier that is used to reference various methods in the cars table. This can be visualized through the diagram below.
As mentioned in the "relevant information" section, the data format used by the API by default is JSON, so the body of the requests must comply. The image below shows the structure that the request body must follow to be correctly interpreted for a brand and a car, respectively.
The default endpoint for creating a brand is */brands*, to create a car, the default endpoint is */:brandId/cars*, where brandId represents a value in a row "id" generated by the API itself when a brand is created, for this reason brands **always come first**.
### GET Requests.
The GET method is used to retrieve data already existing in the database. For brands, it can return a list containing information for all brands or a single brand, for cars, it can return a list containing all registered cars, all cars of a specific brand, or a specific car.
The default endpoint for receiving data for all brands is _/brands_, and for a specific brand is _/brands/:id_, where id represents the value assigned to the brand's id.
As for cars, with the _/cars_ endpoint you receive data on all registered cars, with _/:brandId/cars_ only cars of the brand informed by the id are returned, and to obtain a specific car use the endpoint _/cars/:carId_ where the car id must be entered in the parameter.
### PUT Requests.
The PUT method updates data for a specific brand or car. This request must contain a body with the same JSON structure used to create the data, with the difference that it must only contain the field to be updated and its information.
To update a brand, use the _/brands/:id_ endpoint, and to update a car, use the _/cars/:carId_ endpoint.
### DELETE Requests.
The DELETE method is quite self-explanatory, it deletes a specific brand or car. _Note: Be careful with this request, as no type of confirmation has been implemented so far._
To delete a brand, use the _/brands/:id_ endpoint, and to delete a car, use the _/cars/:carId_ endpoint.
**All of these endpoints can be modified and consulted in the "routes.js" file, found directly in the "src" folder.**
## Contributions
Contributions to this project are welcome! If you have any suggestions or improvements, feel free to open an issue or submit a pull request.