Code Monkey home page Code Monkey logo

django-tastypie-batch's Introduction

Django Tastypie Batch

Adds a batch request endpoint to tastypie Api's.

Install

Install from git using pip:

pip install -e git+https://github.com/jonykalavera/django-tastypie-batch.git#egg=django-tastypie-batch

Add tastypie_batch to your INSTALLED_APPS.

Usage guide

Use the custom BatchApi instead of tastypie's Api class,

from batch.api import BatchApi

v1_api = BatchApi(api_name='v1')

or the namespaced version.

from batch.api import NamespacedBatchApi

v1_api = NamespacedBatchApi(api_name='v1', urlconf_namespace='ns')

Alternatively, you can use the provided mixin to add to your own custom Api.

from batch.api import BatchEndpointMixin
from tastypie.api import Api


class CustomApi(BatchEndpointMixin, Api):
    """
    Custom tastypie Api
    """
    # ...

Making batch requests

a list of request descriptors must be posted to the batch endpoint.

[
    {
        "path": "/api/v1/foo/",
        "params": {
            "limit": 1
        }
    },
    {
        "path": "/api/v1/bar/",
        "params": {
            "limit": 1
        }
    }
]

server will answer with a list of responses for the requested endpoints.

[
  {
    "body": "{\"meta\": {\"limit\": 1, \"next\": \"/api/v1/foo/?limit=1&offset=1\", \"offset\": 0, \"previous\": null, \"total_count\": 2}, \"objects\": [{\"id\": 1, \"name\": \"hello\", \"resource_uri\": \"/api/v1/foo/1/\"}]}",
    "cookies": {},
    "headers": {
      "cache-control": [
        "Cache-Control",
        "no-cache"
      ],
      "content-type": [
        "Content-Type",
        "application/json"
      ],
      "vary": [
        "Vary",
        "Accept"
      ],
      "x-frame-options": [
        "X-Frame-Options",
        "SAMEORIGIN"
      ]
    },
    "params": {
      "limit": 1
    },
    "path": "/api/v1/foo/",
    "status": 200
  },
  {
    "body": "{\"meta\": {\"limit\": 1, \"next\": \"/api/v1/bar/?limit=1&offset=1\", \"offset\": 0, \"previous\": null, \"total_count\": 2}, \"objects\": [{\"id\": 1, \"name\": \"hello\", \"resource_uri\": \"/api/v1/bar/1/\"}]}",
    "cookies": {},
    "headers": {
      "cache-control": [
        "Cache-Control",
        "no-cache"
      ],
      "content-type": [
        "Content-Type",
        "application/json"
      ],
      "vary": [
        "Vary",
        "Accept"
      ],
      "x-frame-options": [
        "X-Frame-Options",
        "SAMEORIGIN"
      ]
    },
    "params": {
      "limit": 1
    },
    "path": "/api/v1/bar/",
    "status": 200
  }
]

ToDo's

  • test cases.
  • POST, PUT, PATCH, DELETE ¿?
  • test other authentication methods.
  • test other serialization methods besides json.

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.