Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from aiohttp import web
from routes import setup_routes
from aiohttp_swagger import *


app = web.Application()
setup_routes(app)
setup_swagger(app,swagger_url='/swagger',swagger_from_file="swagger.yaml")
web.run_app(app,host='127.0.0.1')

8 changes: 1 addition & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,5 @@ python3 main.py
```
* Requests

Your data is in quotation marks " ".
```
curl -X GET -d http://0.0.0.0:8080/students
curl -X DELETE http://0.0.0.0:8080/students/id
curl -X POST -d 'name="your name"&surname="your surname"' http://0.0.0.0:8080/students/"id"
curl -X PUT -d 'surname="your name"&surname="your surname"' http://0.0.0.0:8080/students/"id"
```
All requests can be seen and tested in http://localhost:8080/swagger
You can also display the GET request in the browser by entering the appropriate address.
3 changes: 1 addition & 2 deletions routes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from aiohttp import web
from views import homepagehandler,gethandler,getidhandler,putidhandler,postidhandler,deleteidhandler
from views import gethandler,getidhandler,putidhandler,postidhandler,deleteidhandler

def setup_routes(app):
app.add_routes([
web.get('/',homepagehandler),
web.get('/students',gethandler),
web.get('/students/{id}',getidhandler),
web.put('/students/{id}',putidhandler),
Expand Down
122 changes: 122 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@


---
swagger: "2.0"
info:
title: REST API
description: description in repository on github https://github.com/Raskolnikofff/StudyWebServerRestFullAPI
version: "1.0"
tags:
- name: "student on course"
description: "Everything about your student"
paths:
/students:
get:
summary: "find all students on course"
tags:
- "student on course"
responses:
'200':
description: 'OK'
schema:
$ref: "#/definitions/student"
/students/{id}:
get:
parameters:
- name: "id"
in: "path"
description: "ID of student to return"
required: true
type: "integer"
format: "int64"
summary: "Find students with ID"
tags:
- "student on course"
responses:
'200':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the schema of the response? Since the student is a complex object, just 200 OK is not enough.

description: 'OK'
schema:
$ref: "#/definitions/student"
post:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic error at paths./students/{id}.post
Operations with parameters of "in: formData" must include "application/x-www-form-urlencoded" or "multipart/form-data" in their "consumes" property
Jump to line 44

Check with https://editor.swagger.io/

consumes:
- "application/x-www-form-urlencoded"
parameters:
- name: "id"
in: "path"
description: "ID of student to return"
required: true
type: "integer"
format: "int64"
- name: 'name'
in: 'formData'
description: "students name"
required: true
type: "string"
- name: 'surname'
in: 'formData'
description: "students surname"
required: true
type: "string"
summary: "new student with ID"
tags:
- "student on course"
responses:
'200':
description: 'OK'
schema:
$ref: "#/definitions/student"
'409':
description: 'user with this id exists'
put:
consumes:
- "application/x-www-form-urlencoded"
parameters:
- name: "id"
in: "path"
description: "ID of student to change"
required: true
type: "integer"
format: "int64"
- name: 'name'
in: 'formData'
description: "students name"
required: true
type: "string"
- name: 'surname'
in: 'formData'
description: "students surname"
required: true
type: "string"
summary: "update an existing student with id"
tags:
- "student on course"
responses:
'200':
description: 'OK'
schema:
$ref: "#/definitions/student"
delete:
parameters:
- name: "id"
in: "path"
description: "ID of student to delete in DataBase"
required: true
type: "integer"
format: "int64"
summary: "delete student with id"
tags:
- "student on course"
responses:
'204':
description: "No Content"
definitions:
student:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
surname:
type: "string"
4 changes: 1 addition & 3 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ async def postinfo(request):
surname=data['surname']
return name,surname

def homepagehandler(request):
return web.FileResponse('website/index.html')

def gethandler(request):
with open('DataBase.txt') as dbfile:
data = list()
Expand Down Expand Up @@ -53,6 +50,7 @@ def deleteidhandler(request):
with open('DataBase.txt', 'w') as dbfilewr:
b=dbfile.read()
print((a+b)[:-1],file=dbfilewr)
return web.Response(status=204)
a+=user
return

Expand Down