Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Commit 9e0baba

Browse files
committed
add documentation
1 parent 942c5af commit 9e0baba

20 files changed

+13409
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# for MacOS
2+
.DS_Store

README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# fullstack_tutorial
1+
# Full- Stack Tutorial
2+
3+
\- Author: Jack Jiang
4+
5+
\- Date: Jul. 2019
6+
7+
8+
9+
## Create front-end from scratch
10+
11+
### Prerequisite
12+
13+
- [Node.js](https://nodejs.org)
14+
15+
### Create React Project
16+
17+
```shell
18+
npx create-react-app frontend # create basic react app
19+
npm install --save reactstrap react react-dom # install essitial modules
20+
```
21+
22+
23+
24+
## Create back-end from scratch
25+
26+
### prerequisite
27+
28+
- [Anaconda (Python 3)](https://www.anaconda.com/distribution/#download-section)
29+
30+
### create Flask Project
31+
32+
```shell
33+
mkdir backend
34+
cd backend
35+
python3 -m venv python_modules # create python environment
36+
source ./python_modules/bin/activate # activate python environment
37+
pip install flask flask-cors # install essitial modules
38+
python -m pip freeze > package.txt # save dependencies to package.txt
39+
deactivate # deactivate python environment
40+
```
41+

backend/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/python_modules
2+
__pycache__

backend/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Flask Back-end Deployment
2+
3+
- Author: Jack Jiang
4+
- Date: Jul. 2019
5+
6+
## Setup
7+
8+
```shell
9+
python3 -m venv python_modules # create python environment
10+
source ./python_modules/bin/activate # activate python environment
11+
python3 -m pip install -r package.txt # install python modules from package.txt
12+
deactivate # deactivate python environment
13+
```
14+
15+
## Run
16+
17+
```shell
18+
source ./python_modules/bin/activate # activate python environment
19+
python main.py # run back-end server
20+
deactivate # deactivate python environment
21+
```
22+
23+
## Install new-package
24+
25+
```shell
26+
source ./python_modules/bin/activate # activate python environment
27+
pip install new-package # install new-package
28+
python -m pip freeze > package.txt # save new-package to package.txt
29+
deactivate # deactivate python environment
30+
```
31+
32+
## References
33+
34+
- [Flask Documentation](https://flask.palletsprojects.com/en/1.1.x/)

backend/main.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Name: main.py
2+
# Author: Jack Jiang
3+
# Date: 2019-07
4+
# Description:
5+
# an simple flask backend
6+
from flask import Flask, json, jsonify
7+
from flask_cors import CORS
8+
9+
10+
############################ Initialization ############################
11+
app = Flask(__name__)
12+
# this essitial for Cross Origin Resource Sharing with React frontend
13+
# https://flask-cors.readthedocs.io/en/latest/
14+
CORS(app)
15+
# use a python dictionary to simulate database
16+
# {
17+
# 1: {"firstName": "Jack", "lastName": "Jiang"},
18+
# 5: {"firstName": "Strong", "lastName": "Dinosaur"},
19+
# 12: {"firstName": "Black", "lastName": "Cat"}
20+
# }
21+
database = {}
22+
23+
24+
########################## API Implementation #########################
25+
@app.route('/names/', methods = ["POST"])
26+
def get_name():
27+
# Create Name
28+
29+
return jsonify(data), 200
30+
31+
32+
############################ Main Function #############################
33+
if __name__ == "__main__":
34+
# run backend server on http://localhost:5000/
35+
app.run(host = 'localhost',port=5000, debug=True)

backend/package.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Click==7.0
2+
Flask==1.1.1
3+
Flask-Cors==3.0.8
4+
itsdangerous==1.1.0
5+
Jinja2==2.10.1
6+
MarkupSafe==1.1.1
7+
six==1.12.0
8+
Werkzeug==0.15.4

documentation/README.md

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# API Documentation
2+
3+
- Author: Jack Jiang
4+
- Date: Jul. 2019
5+
6+
### [Summary of HTTP Methods for RESTful APIs](https://restfulapi.net/http-methods/)
7+
8+
| **HTTP Method** | CRUD Function |
9+
| --------------- | ------------- |
10+
| POST | Create |
11+
| GET | Read |
12+
| PUT | Update |
13+
| DELETE | Delete |
14+
15+
16+
17+
## Create Name
18+
19+
### Send
20+
21+
- URL: @server/names/
22+
- HTTP Method: POST
23+
- Content:
24+
25+
```json
26+
{
27+
"id": @id,
28+
"firstName": "Jack",
29+
"LastName": "Jiang"
30+
}
31+
```
32+
33+
### Response
34+
35+
**Succeed**
36+
37+
- HTTP Status Code: 200
38+
- Content:
39+
40+
```json
41+
{
42+
"id": @id,
43+
"firstName": "Jack",
44+
"LastName": "Jiang"
45+
}
46+
```
47+
48+
**Fail**
49+
50+
- HTTP Status Code: 409
51+
- Content:
52+
53+
```json
54+
{
55+
"id": @id,
56+
"errorMsg": "id already exist"
57+
}
58+
```
59+
60+
61+
62+
## Read Name
63+
64+
### Send
65+
66+
- URL: @server/names/@id
67+
- HTTP Method: GET
68+
- Content: Null
69+
70+
### Response
71+
72+
**Succeed**
73+
74+
- HTTP Status Code: 200
75+
- Content:
76+
77+
```json
78+
{
79+
"id": @id,
80+
"firstName": "Jack",
81+
"LastName": "Jiang"
82+
}
83+
```
84+
85+
**Fail**
86+
87+
- HTTP Status Code: 404
88+
- Content:
89+
90+
```json
91+
{
92+
"id": @id,
93+
"errorMsg": "id not found"
94+
}
95+
```
96+
97+
98+
99+
## Update
100+
101+
### Send
102+
103+
- URL: @server/names/@id
104+
- HTTP Method: PUT
105+
- Content:
106+
107+
```json
108+
{
109+
"firstName": "Jack",
110+
"LastName": "Jiang"
111+
}
112+
```
113+
114+
### Response
115+
116+
**Succeed**
117+
118+
- HTTP Status Code: 200
119+
- Content:
120+
121+
```json
122+
{
123+
"id": @id,
124+
"firstName": "Jack",
125+
"LastName": "Jiang"
126+
}
127+
```
128+
129+
**Fail**
130+
131+
- HTTP Status Code: 404
132+
- Content:
133+
134+
```json
135+
{
136+
"id": @id,
137+
"errorMsg": "id not found"
138+
}
139+
```
140+
141+
142+
143+
144+
## Delete
145+
146+
### Send
147+
148+
- URL: @server/names/@id
149+
- HTTP Method: DELETE
150+
- Content: Null
151+
152+
### Response
153+
154+
**Succeed**
155+
156+
- HTTP Status Code: 200
157+
- Content:
158+
159+
```json
160+
{
161+
"id": @id,
162+
"firstName": "Jack",
163+
"LastName": "Jiang"
164+
}
165+
```
166+
167+
**Fail**
168+
169+
- HTTP Status Code: 404
170+
- Content:
171+
172+
```json
173+
{
174+
"id": @id,
175+
"errorMsg": "id not found"
176+
}
177+
```

frontend/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

frontend/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Flask Back-end Deployment
2+
3+
- Author: Jack Jiang
4+
- Date: Jul. 2019
5+
6+
## Setup
7+
8+
```shell
9+
npm install
10+
```
11+
12+
## Run
13+
14+
```shell
15+
npm start
16+
```
17+
18+
## Install new-package
19+
20+
```shell
21+
npm install --save new-package
22+
```
23+
24+
## References
25+
26+
- [React Documentation](https://reactjs.org/docs/getting-started.html)
27+
- [Reactstrap Documentation](https://reactstrap.github.io/components/)

0 commit comments

Comments
 (0)