Read and create blogs.
This application uses npm packages express
, express-handlebars
, express-session
, sequelize
, connection-session-sequelize
, bcrypt
, mysql2
and dotenv
.
CRUD API calls are also defined for back end development allow a developer to test requests using Insomnia to prepare for front-end integration in the future.
As defined in Issues, my future direction for submitted includes options to create Categories and Tags on the front end, as well as select them while creating a Blog. Currently they can only be created from the back end.
I made this application to learn about full-stack applications created with Model-View-Controller, and I used GitHub Projects and various Pull Requests to create this app: https://github.com/leoelicos/submitted/projects/1
Visit submitted on a browser on a computer or mobile.
TBVideoDemo.mp4
Video is also on YouTube: https://youtu.be/E2-GN5ZVDKY
Programs | Download links |
---|---|
Node |
https://nodejs.org/en/download/ |
Mysql |
https://dev.mysql.com/downloads/installer/ |
Insomnia |
https://insomnia.rest/download |
git clone https://github.com/leoelicos/submitted.git
cd submitted
mv .env.Example .env
Input your Mysql credentials. Don't forget to save!
DB_USER={username}
DB_PASSWORD={password}
cd db
mysql -u root -p
{password}
source schema.sql;
exit
cd ..
npm install
npm run seed
npm start
All URLs start with http://localhost:3001/api/
.
No API key is required. You will need to either log in, or sign up and be logged in, in order to receive the responses.
GET request to /{type}
searches for items which have a specified type.
Possible types include:
- blogs:
blog
- categories:
category
- tags:
tag
- blog-tags links:
blogtag
- comments:
comment
- users:
user
Example:
GET http://localhost:3001/api/blog
GET request to /{type}/{id}
searches for items which have a specified type and specified id.
Possible types include:
- a blog:
blog
- a blog category:
category
- a tag:
tag
- a blog-tag link:
blogtag
- a comment:
comment
- a user:
user
Example:
GET http://localhost:3001/api/blog/1
POST request to /{type}/
adds an item of the specified type. You need to include a JSON with a valid body.
Possible types and the JSON body:
{type} |
JSON |
---|---|
blog |
{ "title": STRING, "user_id": INTEGER, "category_id": INTEGER, "summary": STRING, "text": STRING } |
blogtag |
{ "blog_id": INTEGER, "tag_id": INTEGER } |
category |
{ "category_name": STRING } |
comment |
{ "text": STRING, "user_id": INTEGER, "blog_id": INTEGER } |
tag |
{ "tag_name": STRING } |
user |
{ "username": STRING, "password": STRING } |
Example
POST http://localhost:3001/api/tags/
{ "tag_name": "Express" }
PUT request to /{type}/{id}
edits an item of the specified type. You need to include a JSON with a valid body.
Possible types and the JSON body:
{type} |
JSON |
---|---|
blog |
{ "title": STRING, "user_id": INTEGER, "category_id": INTEGER, "summary": STRING, "text": STRING } |
blogtag |
{ "blog_id": INTEGER, "tag_id": INTEGER } |
category |
{ "category_name": STRING } |
comment |
{ "text": STRING, "user_id": INTEGER, "blog_id": INTEGER } |
tag |
{ "tag_name": STRING } |
user |
{ "username": STRING, "password": STRING } |
Example
PUT http://localhost:3001/api/comment/1
{ "text": "Good advice!", "user_id": 2, "blog_id": 1 }
DELETE request to /{type}/{id}
deletes items which have a specified type and specified id.
Possible types include:
- a blog:
blog
- a blog category:
category
- a tag:
tag
- a blog-tag link:
blogtag
- a comment:
comment
- a user:
user
Example:
DELETE http://localhost:3001/api/category/1
Request:
GET http://localhost:3001/api/category
Response:
[
{
"id": 1,
"category_name": "Homework"
},
{
"id": 2,
"category_name": "Challenges"
},
{
"id": 3,
"category_name": "Projects"
},
{
"id": 4,
"category_name": "Mini-projects"
}
]
- BCS Resources
- Normalize.css
© Leo Wong [email protected]
Licensed under the MIT License.