Django app for send sync requests to microservices or external APIs.
Project description
Django application for make sync requests (REST API) between microservices or external APIs.
If you don’t have any microservices yet, you can try to use Django template
Quickstart
Installation
Install the package
$ pip install django-microservice-request
Usage (Google Captcha example)
settings.py
GOOGLE_CAPTCHA_URL = "https://google.com/recaptcha/api/siteverify"
GOOGLE_CAPTCHA_SECRET_KEY = os.environ.get("GOOGLE_CAPTCHA_SECRET_KEY")
services.py
from django.conf import settings
from microservice_request.services import ConnectionService
class GoogleCaptchaService(ConnectionService):
service = settings.GOOGLE_CAPTCHA_URL
secret_key = settings.GOOGLE_CAPTCHA_SECRET_KEY
def validate_captcha(self, captcha: str) -> dict:
params = {
"secret": self.secret_key,
"response": captcha,
}
response = self.service_response(method="get", params=params)
return response.data
serializers.py
from .services import GoogleCaptchaService
class CaptchaMixinSerializer(serializers.Serializer):
captcha = serializers.CharField()
def validate_captcha(self, captcha: str) -> str:
service = GoogleCaptchaService()
response_data = service.validate_captcha(captcha)
if not response_data.get("success"):
raise serializers.ValidationError("Captcha validation error")
return captcha
class LoginSerializer(CaptchaMixinSerializer):
login = serializers.CharField()
password = serializers.CharField()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-microservice-request-0.5.3.tar.gz
.
File metadata
- Download URL: django-microservice-request-0.5.3.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd755e8ac3168b2faf6a28c6c0898e6c8dcd7283038d9a0fb9e9465ea1f41eff |
|
MD5 | 57a96f6d17748a49faf5bcb214c268e1 |
|
BLAKE2b-256 | 388514ac08076f5cb4b3f8eaecf5c3085d41ad01e5b459f0c46bdd43ba63a2be |
File details
Details for the file django_microservice_request-0.5.3-py3-none-any.whl
.
File metadata
- Download URL: django_microservice_request-0.5.3-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1354e0b306dcfc99531e3da218af9c8811259cb2ad152a6f1b41240e1541890 |
|
MD5 | a879ec14710d70f3ba3feaac5d25722c |
|
BLAKE2b-256 | 84052df07c841ad74d2dccdcb68f87ae893fcaa8d474e26bb5b64d5f114047e6 |