Portfolio api
Portfolio api with Django and Django RestFramework
https://github.com/piotrr79/portfolioApi
from rest_framework.decorators import api_view
from rest_framework import exceptions
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from portfolioApi.serializers import ArticleSerializer
from portfolioApi.models import Article
class ArticleItems(APIView):
"""
ArticleItems class
"""
permission_classes = (IsAuthenticated)
def __init__(self):
pass
# article?title=Contact
@api_view(['GET'])
def article(request):
title = request.GET.get('title', None)
if title is None or title == '':
raise exceptions.ParseError('Request url is missing title query param')
results = Article.objects.filter(title__contains=title)
if not results:
raise exceptions.NotFound()
serializer = ArticleSerializer(results, many=True)
return Response(serializer.data)
Portfolio api application written with Django 3.1, Django RestFramework and Python 3. To install and run follow GitHub Readme file.
Once set up just run with
python3 manage.py runserver
and go to http://127.0.0.1:8000/
To obtain JWT post to
http://127.0.0.1:8000/api/token/
user and password as raw data {"username": "youruser", "password": "yourpassword"}
from Postman or use below paylod:
curl --location --request POST 'http://127.0.0.1:8000/api/token/' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "apiuser",
"password": "admin"
}'