Giter Club home page Giter Club logo

django_rest's Introduction

Django_rest

An API created with the Django Rest Framework

Here I have followed the tutorial from https://www.django-rest-framework.org/ to learn how to create an API. I learned how to make Serializers, define their fields by using Django Rest Framework's Serializers class HyperlinkedModelSerializer, to represent relationships using a URL instead of a primary key. Using a URL instead makes the API easier to understand, they can see the whole resources URL and don't need to find documentation to clarify. It also makes it so you don't have to construct resource URLs in the frontend when you want to retrieve related objects. This was my introduction to the Meta Class and type. The tutorial guided me in naming the URL patterns.

I made use of Django's class based views and Django Rest Framework decorators to include the Serializers I made and DRF's Permissions to handle authentication. I use the DRF's Viewsets to provide CRUD procedures.

I created a permissions.py file to custom define object level permissions in the class IsOwnerOrReadOnly which we import into views to restrict updating to only authenticated users and create another user class for looking at snippets without accessing them. We build the IsOwnerOrReadOnly from DRF's BasePermission class from Permissions.

I also make use of the ReadOnlyModelViewSet class from Django Rest Framework's viewsets to create the read only views. Then multiple views are created from each ViewSet class by binding the HTTP methods to the action for each view and registering them with the URL conf utilizing format_suffix_patterns to provide an endpoint for the API.
The tutorial uses the browsable API so you can login and create snippets in the browser.

http responses image
browsable API image logged into browsable API image choosing data format image data in API format image data in JSON format image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.