国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

10-django——RESTful API 之序列化

Bowman_han / 2470人閱讀

摘要:之序列化前后端分離就是前臺(tái)的開發(fā)和后臺(tái)的開發(fā)分離,這個(gè)技術(shù)方案的實(shí)現(xiàn)需要借助,簡(jiǎn)單來(lái)說(shuō)就是開發(fā)人員提供編程的接口被其他人調(diào)用,調(diào)用之后會(huì)返回?cái)?shù)據(jù)供其使用安裝什么是序列化把模型對(duì)象轉(zhuǎn)換為格式然后響應(yīng)出去,便于客戶端進(jìn)行數(shù)據(jù)解析創(chuàng)建序列化類在應(yīng)

Django RESTful API之序列化

前后端分離:就是前臺(tái)的開發(fā)和后臺(tái)的開發(fā)分離,這個(gè)技術(shù)方案的實(shí)現(xiàn)需要借助API,簡(jiǎn)單來(lái)說(shuō)就是開發(fā)人員提供編程的接口被其他人調(diào)用,調(diào)用之后會(huì)返回?cái)?shù)據(jù)供其使用

安裝pip install djangorestframework

什么是序列化?:把模型對(duì)象轉(zhuǎn)換為JSON格式然后響應(yīng)出去,便于客戶端進(jìn)行數(shù)據(jù)解析

創(chuàng)建序列化類

在應(yīng)用目錄下創(chuàng)建名為serializers.py的文件

from rest_framework import serializers
from myApp.models import Student, Grade
#給學(xué)生類創(chuàng)建序列化類
class StudentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Student
        fields = ("id", "name", "sex", "age", "content", "isDelete", "grade")
#該班級(jí)創(chuàng)建序列化類
class GradeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Grade
        fields = ("id", "name", "boyNum", "girlNum", "isDelete")
使用系列化

進(jìn)入shell環(huán)境:python manage.py shell

引入序列化類,創(chuàng)建序列化對(duì)象查看可序列化的字段:

>>> from myApp.serializers import StudentSerializer
>>> serializer = StudentSerializer()
>>> print(serializer)
StudentSerializer():
    id = IntegerField(label="ID", read_only=True)
    name = CharField(max_length=20)
    sex = BooleanField(required=False)
    age = IntegerField(max_value=2147483647, min_value=-2147483648)
    contend = CharField(max_length=40)
    isDelete = BooleanField(label="IsDelete", required=False)
    grade = PrimaryKeyRelatedField(queryset=Grade.objects.all())

找到一個(gè)學(xué)生:

>>> from myApp.models import Student
>>> stu = Student.objects.get(pk=1)
>>> print(stu)
薛延美

依據(jù)學(xué)生創(chuàng)建序列化對(duì)象,再對(duì)對(duì)象進(jìn)行序列化操作:

>>> serializer = StudentSerializer(stu)
>>> print(serializer.data)
{"id": 1, "name": "薛延美", "sex": False, "age": 20, "contend": "我叫薛延美", "isDelete": False, "grade": 4}
>>> print(type(serializer.data))

將數(shù)據(jù)渲染成JSON格式

>>> from rest_framework.renderers import JSONRenderer
>>> content = JSONRenderer().render(serializer.data)
>>> print(content)
b"{"id":1,"name":"xe8x96x9bxe5xbbxb6xe7xbex8e","sex":false,"age":20,"contend":"xe6x88
x91xe5x8fxabxe8x96x9bxe5xbbxb6xe7xbex8e","isDelete":false,"grade":4}"

反序列化:當(dāng)客戶需要修改、增加、刪除數(shù)據(jù)時(shí),就要這個(gè)過(guò)程反過(guò)來(lái),就叫反序列化

>>> from rest_framework.parsers import JSONParser
>>> from django.utils.six import BytesIO
>>> stream = BytesIO(content)
>>> print(stream)
<_io.BytesIO object at 0x000001EECF597E08>
>>> stu2 = JSONParser().parse(stream)
>>> print(stu2)
{"id": 1, "name": "薛延美", "sex": False, "age": 20, "contend": "我叫薛延美", "isDelete": False, "grade": 4}
>>> print(type(stu2))

檢測(cè)數(shù)據(jù)并保存

>>> stu2.save()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: "dict" object has no attribute "save"
>>> serializer = StudentSerializer(data=stu2)
>>> print(serializer.is_valid())
True
>>> print(serializer.validated_data)
OrderedDict([("name", "薛延美"), ("sex", False), ("age", 20), ("contend", "我叫薛延美"), ("isDel
ete", False), ("grade", )])
>>> print(type(serializer.validated_data))

>>> print(serializer.validated_data["name"])
薛延美
>>> serializer.save()
視圖實(shí)現(xiàn)使用序列化
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse

from myApp.models import Student, Grade

from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser
from django.utils.six import BytesIO

from myApp.serializers import StudentSerializer, GradeSerializer

def studentsList(request):
    if request.method == "GET":
        stus = Student.objects.all()
        #序列化
        serializer = StudentSerializer(stus, many=True)
        return JsonResponse(serializer.data, safe=False)
    elif request.method == "POST":
        # content = JSONRenderer().render(request.POST)
        # stream = BytesIO(content)
        # stuDict = JSONParser().parse(stream)
        # serializer = StudentSerializer(data=stuDict)
        serializer = StudentSerializer(data=request.POST)
        if serializer.is_valid():
            #存數(shù)據(jù)
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse({"error":serializer.errors}, status=400)
def studentDetail(request, pk):
    try:
        stu = Student.objects.get(pk=pk)
    except Student.DoesNotExist as e:
        return JsonResponse({"error":str(e)}, status=404)

    if request.method == "GET":
        serializer = StudentSerializer(stu)
        return JsonResponse(serializer.data)
    elif request.method == "PUT":
        #content = JSONRenderer().render(request.data)
        #stream = BytesIO(content)
        #stuDict = JSONParser().parse(stream)
        # print(stuDict)
        #修改
        serializer = StudentSerializer(stu, data=request.data)
        if serializer.is_valid():
            #存數(shù)據(jù)
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse({"error":serializer.errors}, status=400)
    elif request.method == "DELETE":
        stu.delete()
        return HttpResponse(status=204,content_type="application/json")
Django RESTful API 之請(qǐng)求與響應(yīng) 激活應(yīng)用
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "myApp",
    "rest_framework",
]
Request對(duì)象
request.POST: 只能處理表單數(shù)據(jù),并且只能處理POST請(qǐng)求

擴(kuò)展: request.data 能處理各種請(qǐng)求的數(shù)據(jù),可以處理PUT和PATCH請(qǐng)求的數(shù)據(jù)

Response對(duì)象
HttpResponse、JsonResponse類: 用于返回json數(shù)據(jù),在return的時(shí)候需要指明json格式

擴(kuò)展: Reponse類 會(huì)根據(jù)客戶端的請(qǐng)求頭信息返回正確的內(nèi)容類型

狀態(tài)碼
發(fā)送http請(qǐng)求會(huì)返回各種各樣的狀態(tài)碼,但是狀態(tài)碼都是數(shù)字,不能夠明確的讓程序員了解是什么問(wèn)題

擴(kuò)展 HTTP_400_BAD_REQUEST 極大提高了可讀性

視圖

@api_view: 是裝飾器,用在基于函數(shù)的視圖上

APIView: 是類,用在基于類的視圖上

作用: 提供一些功能,讓程序員省去了很多工作,確保在視圖中收到request對(duì)象或在對(duì)象中添加上下文 裝飾器可以在接收到輸入錯(cuò)誤的request.data時(shí)拋出ParseError異常,在適當(dāng)?shù)臅r(shí)候返回405狀態(tài)碼

代碼
# from django.shortcuts import render
# from django.http import HttpResponse, JsonResponse
from myApp.models import Student, Grade

# from rest_framework.renderers import JSONRenderer
# from rest_framework.parsers import JSONParser
# from django.utils.six import BytesIO

from myApp.serializers import StudentSerializer

from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(["GET", "POST"])
def studentsList(request):
    if request.method == "GET":
        stus = Student.objects.all()
        #序列化
        serializer = StudentSerializer(stus, many=True)
        # 不需要指定json格式,返回客戶端可以返回json或者HTML,返回HTML內(nèi)容的話,會(huì)在瀏覽器中經(jīng)過(guò)渲染成頁(yè)面
        return Response(serializer.data, status=status.HTTP_200_OK)
    elif request.method == "POST":
        # content = JSONRenderer().render(request.POST)
        # stream = BytesIO(content)
        # stuDict = JSONParser().parse(stream)
        serializer = StudentSerializer(data=request.data)
        if serializer.is_valid():
            #存數(shù)據(jù)
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response({"error":serializer.errors}, status=status.HTTP_400_BAD_REQUEST)

@api_view(["GET", "PUT", "DELETE"])
def studentDetail(request, pk):
    try:
        stu = Student.objects.get(pk=pk)
    except Student.DoesNotExist as e:
        return Response({"error":str(e)}, status=status.HTTP_404_NOT_FOUND)

    if request.method == "GET":
        serializer = StudentSerializer(stu)
        return Response(serializer.data)
    elif request.method == "PUT":
        # content = JSONRenderer().render(request.POST)
        # stream = BytesIO(content)
        # stuDict = JSONParser().parse(stream)
        # print(stuDict)
        #修改
        serializer = StudentSerializer(stu, data=request.data)
        if serializer.is_valid():
            #存數(shù)據(jù)
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response({"error":serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
    elif request.method == "DELETE":
        stu.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
向URL添加可選的后綴 視圖
def studentsList(request, format=None):
def studentDetail(request, pk, format=None):
路由
from django.conf.urls import url
from myApp import views
#格式后綴
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
    # GET /students/
    # POST /students/
    url(r"^students/$", views.studentsList),
    # GET /students/id
    # PUT /students/id
    # PATCH /students/id
    # DELETE /students/id
    url(r"^students/(?Pd+)/$", views.studentDetail),
]
urlpatterns = format_suffix_patterns(urlpatterns)
測(cè)試
http://127.0.0.1:8000/students.api
http://127.0.0.1:8000/students.json
Django RESTful API 之基于類的視圖 把視圖變成類
from myApp.models import Student
from myApp.serializers import StudentSerializer
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from django.http import Http404

class StudentsList(APIView):
    def get(self, request, format=None):
        stus = Student.objects.all()
        serializer = StudentSerializer(stus, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
    def post(self, request, format=None):
        serializer = StudentSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response({"error": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)

class StudentDetail(APIView):
    def getObject(self, pk):
        try:
            return Student.objects.get(pk=pk)
        except Student.DoesNotExist as e:
            raise Http404
    def get(self, request, pk, format=None):
        stu = self.getObject(pk)
        serializer = StudentSerializer(stu)
        return Response(serializer.data)
    def put(self, request, pk, format=None):
        stu = self.getObject(pk)
        serializer = StudentSerializer(stu, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response({"error": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
    def delete(self, request, pk, format=None):
        stu = self.getObject(pk)
        stu.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
修改路由匹配類視圖
from django.conf.urls import url
from myApp import views
#格式后綴
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
    # GET /students/
    # POST /students/
    url(r"^students/$", views.StudentsList.as_view()),
    # GET /students/id
    # PUT /students/id
    # PATCH /students/id
    # DELETE /students/id
    url(r"^students/(?Pd+)/$", views.StudentDetail.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
優(yōu)點(diǎn)

把各種HTTP請(qǐng)求分離開

可以輕松構(gòu)成可重復(fù)使用的行為

可以大大簡(jiǎn)化代碼

增加了可讀性

使用Mixins類

基本使用

from myApp.models import Student
from myApp.serializers import StudentSerializer
from rest_framework import mixins, generics

#父類中有且只有一個(gè)能繼承自APIView類
class StudentsList(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)
    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

class StudentDetail(mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, generics.GenericAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    def get(self, request, *args, **kwargs):
        return self.retrieve(request, *args, **kwargs)
    def put(self, request, *args, **kwargs):
        return self.update(request, *args, **kwargs)
    def delete(self, request, *args, **kwargs):
        return self.destroy(request, *args, **kwargs)

通用視圖使用

from myApp.models import Student
from myApp.serializers import StudentSerializer
from rest_framework import generics
class StudentsList(generics.ListCreateAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
class StudentDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
Django RESTful API 之認(rèn)證和權(quán)限

如果沒(méi)有權(quán)限認(rèn)證功能,任何資源都會(huì)被任何用戶隨意修改,所以實(shí)現(xiàn)如下功能

Student與其創(chuàng)建者相互關(guān)聯(lián)

只有經(jīng)過(guò)身份驗(yàn)證(登陸)的用戶才可以創(chuàng)建Student對(duì)象

只有創(chuàng)建該Student對(duì)象的用戶才可以對(duì)齊進(jìn)行更新或者刪除

未經(jīng)驗(yàn)證的用戶只有訪問(wèn)(只讀)的功能

給學(xué)生添加所屬用戶字段:owner = models.ForeignKey("auth.User", related_name="students")

重新生成表

創(chuàng)建幾個(gè)用戶 python manage.py createsuperuser

在serializers.py文件中給User添加序列化類

from django.contrib.auth.models import User
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ("id", "username", "students")
增加用戶的接口

路由

from django.conf.urls import url
from myApp import views
#格式后綴
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
    url(r"^students/$", views.StudentsList.as_view()),
    url(r"^students/(?Pd+)/$", views.StudentDetail.as_view()),

    url(r"^users/$", views.UsersList.as_view()),
    url(r"^users/(?Pd+)/$", views.UserDetail.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)

視圖

from django.contrib.auth.models import  User
class UsersList(generics.ListCreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
class UserDetail(generics.RetrieveDestroyAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
把Student和User關(guān)聯(lián)

概述: 還不能把Student和User關(guān)聯(lián),因?yàn)樵谑褂玫臅r(shí)候User的數(shù)據(jù)時(shí)通過(guò)Request傳入的,而不是以序列化數(shù)據(jù)傳遞的,此時(shí)剛才添加了一個(gè)owner作為外鍵,此時(shí)使用外鍵

class StudentsList(generics.ListCreateAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    
    #讓用戶在通過(guò)post請(qǐng)求創(chuàng)建一個(gè)新的student時(shí),在保證創(chuàng)建學(xué)生時(shí)會(huì)把request中的user賦值給該學(xué)生的owner字段
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)
在顯示學(xué)生時(shí)還需要顯示學(xué)生屬于哪個(gè)用戶
class StudentSerializer(serializers.ModelSerializer):
    class Meta:
        owner = serializers.ReadOnlyField(source="owner.username")
        model = Student
        fields = ("id", "name", "sex", "age", "contend", "isDelete", "grade", "owner")
添加權(quán)限
from rest_framework import permissions
class StudentsList(generics.ListCreateAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    #讓用戶在通過(guò)post請(qǐng)求創(chuàng)建一個(gè)新的student時(shí),在保證創(chuàng)建學(xué)生時(shí)會(huì)把request中的user賦值給該學(xué)生的owner字段
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)
class StudentDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    # 只有所有者用戶才能刪除、修改,其他用戶只能訪問(wèn)
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
為可瀏覽的API添加登陸功能

工程目錄下與工程目同名目錄下的urls.py文件

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r"^admin/", admin.site.urls),
    url(r"^api-auth/", include("rest_framework.urls", namespace="rest_framework")),
    url(r"^", include("myApp.urls")),
]
添加對(duì)象權(quán)限

要實(shí)現(xiàn)讓所有的Students可以被所有人訪問(wèn),但是每個(gè)學(xué)生只能被其創(chuàng)建者所操作。

需要自定義權(quán)限,讓每個(gè)學(xué)生只能被其創(chuàng)建者所操作,在應(yīng)用目錄下創(chuàng)建permissions.py的文件

from rest_framework import permissions

class IsOwnerOrReadOnly(permissions.BasePermission):
    def has_object_permission(self, request, view, obj):
        if request.method in permissions.SAFE_METHODS:
            # 用戶請(qǐng)求為GET 可以只讀
            return True
        return obj.owner == request.user

添加自定義權(quán)限

from myApp.permissions import IsOwnerOrReadOnly
class StudentDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    # 只有所有者用戶才能刪除、修改,其他用戶只能訪問(wèn)
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
API授權(quán)

由于現(xiàn)在我們還沒(méi)有使用Authentication類,所以項(xiàng)目目前還是使用默認(rèn)的SessionAuthentication和BaseAuthentication

在使用瀏覽器訪問(wèn)API的時(shí)候,瀏覽器會(huì)幫助我們保存會(huì)話信息,所以當(dāng)權(quán)限滿足是就可以對(duì)一個(gè)學(xué)生對(duì)象進(jìn)行刪除或者更新,還可以創(chuàng)建學(xué)生

當(dāng)如果通過(guò)命令來(lái)操作API,我們就必須在每次發(fā)送請(qǐng)求是附帶驗(yàn)證信息 : http://user1:sunck1999@127.0.0.1:8000/students/1/

程序中使用 from django.contrib.auth import login

Django RESTful API 之ViewSet和Routers

目的: 介紹另一種基于類的視圖的寫法,它的抽象程度更高,代碼更少

使用ViewSets重構(gòu)視圖
from myApp.models import Student
from myApp.serializers import StudentSerializer, UserSerializer
from rest_framework import permissions
from myApp.permissions import IsOwnerOrReadOnly
from django.contrib.auth.models import  User
from rest_framework import viewsets

class StudentViewSet(viewsets.ModelViewSet):
    queryset = Student.objects.all()
    serializer_class = StudentSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly)
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

class UserViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
重構(gòu)路由
from django.conf.urls import url, include
from myApp.views import StudentViewSet, UserViewSet
from rest_framework.urlpatterns import format_suffix_patterns

students_list = StudentViewSet.as_view({
    "get":"list",
    "post":"create"
})
student_detail = StudentViewSet.as_view({
    "get":"retrieve",
    "put":"update",
    "patch":"partial_update",
    "delete":"destroy"
})
users_list = UserViewSet.as_view({
    "get":"list"
})
user_detail = UserViewSet.as_view({
    "get":"retrieve"
})
urlpatterns = format_suffix_patterns([
    url(r"^students/$", students_list, name="students_list"),
    url(r"^students/(?Pd+)/$", student_detail, name="student_detail"),
    url(r"^users/$", users_list, name="users_list"),
    url(r"^users/(?Pd+)/$", user_detail, name="user_detail"),
])
使用Routers
from django.conf.urls import url, include
from myApp import views
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r"students", views.StudentViewSet)
router.register(r"users", views.UserViewSet)

urlpatterns = [
    url(r"^", include(router.urls))
]

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/42039.html

相關(guān)文章

  • 9-django——restful設(shè)計(jì)風(fēng)格

    摘要:設(shè)計(jì)風(fēng)格協(xié)議與用戶的通信協(xié)議,總是使用協(xié)議域名應(yīng)該盡量將部署在專用域名之下,如果確定很簡(jiǎn)單,不會(huì)有進(jìn)一步的擴(kuò)展,可以考慮放在主域名之下。數(shù)據(jù)庫(kù)中的表示記錄同種數(shù)據(jù)的集合,所以中的名詞也應(yīng)該使用復(fù)數(shù)。 showImg(https://segmentfault.com/img/bVbdXlE?w=1560&h=913); RESTful Api設(shè)計(jì)風(fēng)格 協(xié)議:API與用戶的通信協(xié)議,總是使...

    scq000 評(píng)論0 收藏0
  • Flask 擴(kuò)展系列 Flask-RESTful

    摘要:勵(lì)以最少的安裝方式進(jìn)行最佳實(shí)踐。上面的例子接收了一個(gè)對(duì)象并準(zhǔn)備將其序列化。裝飾器會(huì)通過(guò)進(jìn)行轉(zhuǎn)換。從對(duì)象中提取的唯一字段是。是一個(gè)特殊的字段,它接受端點(diǎn)名稱并為響應(yīng)中的端點(diǎn)生成一個(gè)。可以查看項(xiàng)查看完整列表。 大綱 簡(jiǎn)介 安裝 快速入門 一個(gè)最小的 api 例子 資源豐富的路由 端點(diǎn) 參數(shù)解析 數(shù)據(jù)格式化 完整 TODO 應(yīng)用例子 簡(jiǎn)介 Flask-RESTful是一個(gè)Flas...

    阿羅 評(píng)論0 收藏0
  • Kubernetes1.5源碼分析(三) apiServergo-restful的使用

    摘要:它包括一組和一個(gè)對(duì)象,使用進(jìn)行請(qǐng)求派發(fā)。流程基本就是這樣,接著我們直接進(jìn)入接口看實(shí)現(xiàn)拼裝然后填充并返回一個(gè)對(duì)象創(chuàng)建一個(gè)這個(gè)是關(guān)鍵,會(huì)對(duì)各種進(jìn)行注冊(cè)增加一個(gè)的將該加入到前兩個(gè)調(diào)用函數(shù)比較簡(jiǎn)單,這里不進(jìn)行介紹了。 源碼版本 Kubernetes v1.5.0 go-restful 簡(jiǎn)介 go-restful是用于構(gòu)建REST-style web服務(wù)的golang包。它是出現(xiàn)時(shí)因?yàn)橐粋€(gè)jav...

    Doyle 評(píng)論0 收藏0
  • Kubernetes1.5源碼分析(二) apiServer資源注冊(cè)

    摘要:我們先將上面的接口解析放放,先看下是如何初始化的路徑定義了,再看路徑定義空的創(chuàng)建,用于不同版本對(duì)象轉(zhuǎn)換增加一些轉(zhuǎn)換函數(shù)上面就創(chuàng)建了一個(gè)空的。其實(shí)就是向添加了轉(zhuǎn)換函數(shù),比如將轉(zhuǎn)換為,將轉(zhuǎn)換為。 源碼版本 Kubernetes v1.5.0 簡(jiǎn)介 k8s里面有各種資源,如Pod、Service、RC、namespaces等資源,用戶操作的其實(shí)也就是這一大堆資源。但這些資源并不是雜亂無(wú)章的,...

    imccl 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<