HELLO! @THETEALPICKLE HERE. Are you a lazy backend coder who loves cheese? Then this is your template.
In the alien hyper-stream (the human equivalent of a mall), a substance once believed to be extinct has resurfaced. This substance, known on Earth as 🧀 cheese, is a highly corrosive weapon 🦠 capable of slowing down higher consciousness evolution. The ultimate weapon in 💣 war.
The Grand Alieness has approved a reconnaissance mission to collect cheese data from every planet. For the mission, given the origins of the weapon, The Grand Alieness has opted for the use of human technology as the data collection method.
Different planets culture cheese with varying toxin levels.
This is the API.
🤖 CheeseVapor is a Swift based server based on cheese 🧀
🙃 Features 🙃
- Authentication [Login/Token]
- Logging
- Model Testing
- Request Testing
🧠 Vapor 3, babyyyyyy 💨
The three databases with Vapor support are sqlite, msql, and postgresql.
This project uses MySQL as its database.
To get this project running on your machine, 3 steps.
- Get a Docker MySQL Database up and Running
- Clone the project to your machine
- Build and run the project
That is all. 🙃
Haha. As if beginner Jessica would understand that shit. 😭
OKAY, some more effort into the explanation, here we go
Brace yourself, more detailed steps coming. Get your cup of water please
You'll first want to get Docker up and running.
Head over to the Docker website and start the download of the Docker Desktop Application
Assuming the link hasn't changed, you should be able to click on 'Docker Desktop Application' above to be directed to the website.
Cool, while that's downloading (can't remember if it took a while, let's assuming it does). Create a docker application. You'll need these credentials to log into the desktop application.
No worries, you won't be charged for anything. F R E E. 💰👍🏾
Up to this point you should have logged into the Docker desktop application with your docker credentials.
Hold up, you haven't started any databases yet. You've set the stage so that you CAN start running databases.
Open up a new Terminal window and type the command
docker run --name mysql -e MYSQL_DATABASE=vapor -e MYSQL_USER=vapor -e MYSQL_PASSWORD=password \
-p 3306:3306 -d mysql/mysql-server:5.7
Hey, Jessica. WTF, did I just type?
Okay.
docker run
The docker command for running a docker database
--name mysql
The database container I want to create can be identified with the name mysql. This is the name you will use when you want to stop, start, and remove your database
-e MYSQL_DATABASE=vapor
Setup the global variable for my mysql database to the value 'vapor'. This is the database reference that is used in your server's configure.swift file for setting up your databse configuration
-e MYSQL_USER=vapor
Setup the global variable for my mysql user to the value 'vapor'. This is the username reference that is used in your server's configure.swift file for setting up your database configuration.
-e MYSQL_PASSWORD=password
Setup the global variable for my mysql password to the value 'password'. This is the password reference that is used in your server's configure.swift file for setting up your database configuration.
-p 3306:3306
Set the port for your docker database to run on port 3306. 3306 is the default MySQL port.
-d
Set the database to be detached. Detached mode is when your database container is running in the background.
mysql/mysql-server:5.7
Specifying which mysql server version to use. In this case, 5.7
Alright, bitch. Welp. That was most of the work.
Take a breathe, almost done.
Easiest method if you don't have ssh setup on your device is to download the zip and unzip it. bam.
HOWEVER, you probably do have SSH setup. If not, but you're interested in doing so (a good thing to do for a secure connection between your machine and your github account). You can follow this article (Assuming the link hasn't changed since writing this 😬).
Yay, project cloned, docker running. Time to build and run. This is it.
Pull up a new terminal window and change directory cd
AKA navigate to your project's folder.
First, you'll want to build your project's dependencies.
vapor build
Now, run your project
vapor run
From here you can use the Postman or RESTed app to test your API endpoints.
Yay, twerk time. 🍑🎉
The main databases supported with Vapor include SQLite, MySQL, and PostgreSQL.
That's cool, but what does that mean?
What are their disadvantages and advantages? Appropriate use cases?
SQLite is a lightweight database used for simple local data storage.
I have found this database type is most useful for data analysis/machine learning.
For example local on device storage of an artificial intelligence model
SQLite also shines when it comes to internet of things devices which often operate without human support.
SQLite does not compete with client/server databases like MySQL or PostgreSQL.
SQLite competes more with standard file management libraries such as fopen().
MySQL was designed for speed and reliability, making it an ideal database for many use cases.
Currently many large applications and sites such as Facebook, Spotify, and Netflix are powered by MySQL.
MySQL's speed and reliability come at the cost of not fully being SQL compliant, so there are some functional limitations depending on your use case.
Disadvantages of MySQL: [SQL compliance and functionality limitations, licence and propriety features, and slowed development]
Advantages of MySQL: [security, speed, replication (useful for horizontal scaling), and popularity/ease of use]
PostgreSQL is the most advanced open-source relational database. PostgreSQL was designed to be highly extensible and standard compliant.