zoukankan      html  css  js  c++  java
  • http协议

    你理解的Http协议?
    - 建立在tcp之上
    - 一次请求一次响应然后断开连接(无状态、短连接)
    - 请求和响应
    发送:请求头 请求体
    host:www.baidu.com content-type:application/json 请求体
    响应:响应头 响应体

    django请求生命周期

    -> 执行遵循wsgi协议的模块(socket服务端)
    -> 中间件(路由匹配)
    -> 视图函数(业务处理:ORM、模板渲染)
    -> 中间件
    -> wsgi返回

     什么wsgi
    web服务网关接口
    实现该协议的模块:
    - wsgiref
    - werkzurg
    - uwsig

    视图
    - FBV
    url - 函数
    - CBV
    url - view

    djang rest framework


     restful 规范(10)
    什么是接口?
    - URL
    - 约束
    # 约束继承(实现)了他的类中必须含有IFoo中的方法
    interface IFoo:
    def func(self): pass


    class Foo(IFoo):
    def func(self):
    print(11111)

    1. 根据method不同,进行不同操作
    GET/POST/PUT/DELETE/PATCH
    2. 面向资源编程
    http://www.luffycity.com/salary

    3. 体现版本
    http://www.luffycity.com/v1/salary
    http://www.luffycity.com/v2/salary

    https://v4.bootcss.com/
    https://v3.bootcss.com/
    4. 体现是API
    http://www.luffycity.com/api/v1/salary
    http://www.luffycity.com/api/v2/salary

    http://api.luffycity.com/v1/salary
    http://api.luffycity.com/v2/salary
    5. https
    https://www.luffycity.com/api/v1/salary
    https://www.luffycity.com/api/v2/salary

    6. 响应式设置状态码
    200
    300
    400
    500
    return HttpResponse('adfasdf',status=300)

    7. 条件
    https://www.luffycity.com/api/v2/salary?page=1&size=10

    8. 返回值
    https://www.luffycity.com/api/v2/salary
    GET: 所有列表
    {
    code: 10000,
    data: [
    {'id':1,'title':'高亮'},
    {'id':1,'title':'龙泰'},
    {'id':1,'title':'小东北'},
    ]
    }

    POST: 返回新增的数据
    {'id':1,'title':'高亮'}

    https://www.luffycity.com/api/v2/salary/1/
    GET: 获取单条数据
    {'id':1,'title':'高亮'}
    PUT:更新
    {'id':1,'title':'高亮'}
    PATCH: 局部更新
    {'id':1,'title':'高亮'}
    DELETE:删除

    9. 返回错误信息
    {
    code: 100001,
    error: 'xxx错误'
    }

    10. Hypermedia API
    ret = {
    code: 1000,
    data:{
    id:1,
    name:'小强',
    depart_id:http://www.luffycity.com/api/v1/depart/8/
    }
    }

    建议大家使用restful规范


    6. django rest framework框架(10)
    - 权限
    - 认证
    - 访问频率限制
    - 序列化
    - 路由
    - 视图
    面试题:你的写的类都继承过哪些类?
    class View(object):

    class APIView(View):

    class GenericAPIView(views.APIView):

    class GenericViewSet(ViewSetMixin, generics.GenericAPIView)

    class ModelViewSet(mixins.CreateModelMixin,
    mixins.RetrieveModelMixin,
    mixins.UpdateModelMixin,
    mixins.DestroyModelMixin,
    mixins.ListModelMixin,
    GenericViewSet):
    - 分页
    - 解析器
    - 渲染器
    - 版本

  • 相关阅读:
    C#动态调用webservice方法
    WinForm客户端调用 WebService时 如何启用Session
    C# 调用 Web Service 时出现 : 407 Proxy Authentication Required错误的解决办法
    ms sql 在任何位置 添加列
    Python requests
    LookupError: unknown encoding: cp65001
    [转]HTTP请求模型和头信息参考
    【原】使用StarUML画用例图
    【微信转载】Google是如何做测试的
    手机SD卡损坏补救措施
  • 原文地址:https://www.cnblogs.com/duhong0520/p/11571840.html
Copyright © 2011-2022 走看看