Giter VIP home page Giter VIP logo

chalice-view's Introduction

Chalice View

travis Coverage Status pypi

Extension classes for develop chalice

installation

$ pip install chalice_view

how to use

Chalice View load your .chalice directory and set your project name and development mode.

you should only create custom view class and register route to custom manager class.

from chalice_view.manager import AppManager
from chalice_view.view import View


# define custom view based on chalice_view.View class
class SampleView(View):
  def get(self, request, name):
    return {'hello': name}


# initialize app manager to generate chalice application
manager = AppManager(debug=True)
manager.register('/version1/{name}', SampleView)
# chalice will read following app instance
app = manager.generate_app()

testing

import unittest
from chalice_view.test import ChaliceRequestFactory

class TestCustomResponse(unittest.TestCase):
  def setUp(self):
    # 1. initialize request factory
    self.factory = ChaliceRequestFactory()
    # 2. generate custom request parser
    self.view = manager.as_view()

  def test_sample(self):
    # 3. create request and call view method
    request = factory.get('/version1/{name}', uri_params={'name': 'kate'})
    response = view(request)
    # call test
    self.assertTrue({'hello': 'kate'}, response)

if __name__ == '__main__':
  unittest.main()

todo

from . import App, View, serializers, router

class SampleSerializer(serializers.Serializer):
  country = serializers.StringField(max_length=20)
  zipcode = serializers.IntegerField(required=False)

class SampleView(View)
  def post(self, request, *args):
    serializer = SampleSerializer(request.json_body)
    if serializer.is_valid:
      return serializer.data
    else:
      return {'error': 'country is required'}
from pynamodb.models import Model
from pynamodb.attributes import (
  UnicodeAttribute, NumberAttribute
)

class AddressModel(Model):
  class Meta:
        table_name = 'Address'

    zipcode = NumberAttribute(hash_key=True)
    prefecture = UnicodeAttribute(range_key=True)

class AddressSerializer(new_serializer.Serializer):
  class Meta:
    model = AddressSerializer

class AddressView(ModelView):
  queries = Address.objects.all()
  serializer = AddressSerializer

chalice-view's People

Watchers

 avatar  avatar

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.