Skip to main content

Soft Way company REST utils.

Project description

# sw-rest-utils
REST helpers


## Declaration
for example in my_app/rest.py
```python
from django.conf import settings
from sw_rest_utils import BaseRest


class SomeResource(BaseRest):
url = settings.OTHER_SERVICE_URL + '/rest/some_resource/'
label = 'Super resource first'


class DynamicallyUrl(BaseRest):
def __init__(self, pk):
self.pk = pk

def get_url(self):
return settings.OTHER_SERVICE_URL + '/rest/some_resource/' + str(self.pk)


class ResourceWithGetParams(BaseRest):
url = settings.OTHER_SERVICE_URL + '/rest/some_resource/'

def __init__(self, some_filter_value):
self.some_filter_value = some_filter_value

def get_params(self):
return {
'some_filter_value': self.some_filter_value
}


class ResourceWithPostParams(BaseRest):
url = settings.OTHER_SERVICE_URL + '/rest/some_resource/'
method = 'PUT'

def __init__(self, some_value):
self.some_value = some_value

def get_data(self):
return {
'some_value': self.some_value
}


class CustomResponseProcess(BaseRest):
url = settings.OTHER_SERVICE_URL + '/rest/some_resource/'

def process_request(self):
result = super().process_request()
result['total'] = result['foo'] + result['bar']
return result


class CustomHeaders(BaseRest):
def get_headers(self):
return {'Authorization': 'Token {0}'.format(settings.AUTH_TOKEN)}

```

## Usage
for example in my_app/views.py
```python
from rest_framework.response import Response
import my_app.rest


def some_view(request):
result = my_app.rest.SomeResource().process_request()
value = result['some_response_value']
return Response({'other_service_result': value})

```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sw-rest-utils-0.0.15.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file sw-rest-utils-0.0.15.tar.gz.

File metadata

File hashes

Hashes for sw-rest-utils-0.0.15.tar.gz
Algorithm Hash digest
SHA256 39ee757574a467b5c5dce3968f1b370ebcab02000b68f390a3477b4cb0fb2b06
MD5 6e4d2db1ca67994a1fe8f1707bccb966
BLAKE2b-256 2d69ff494ab3619dcec26f513e272c3831fc61ea06c6e887f3bf3dd420e18d19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page