Giter VIP home page Giter VIP logo

polls-api's Introduction

Polls API

Apiary Documentation Circle CI Status

This is a Python implementation of a Polls API, an API that allows consumers to view polls and vote in them. Take a look at the API Documentation. We've deployed an instance of this API for testing.

Development Environment

You can configure a development environment with the following:

NOTE: These steps assume you have Python along with pipenv installed.

$ pipenv install
$ pipenv run python manage.py migrate

Running the tests

$ python manage.py test

Running the development server

$ pipenv run python manage.py runserver

Running dredd

Providing dredd has been installed, you can run the following to run dredd against the Polls API:

$ pipenv run dredd

Running via docker

Running the development server

$ docker-compose up web
$ open "http://$(docker-machine ip default):8080"

Running tests in Docker

$ docker-compose run shell python manage.py test

Deploying

Deploying on Heroku

Click the button below to automatically set up the Polls API in an app running on your Heroku account.

Deploy to Heroku

Once you've deployed, you can easily clone the application and alter the configuration to disable features:

$ heroku clone -a new-app-name
$ heroku config:set POLLS_CAN_VOTE_QUESTION=false
$ heroku config:set POLLS_CAN_CREATE_QUESTION=false
$ heroku config:set POLLS_CAN_DELETE_QUESTION=false

Deploying on Heroku using Docker

If you'd like to, you may use Docker on Heroku instead. Refer to the Heroku Container Registry and Runtime Guide for detailed instructions. Providing you have Docker installed you can follow the following steps:

$ heroku container:login
$ heroku container:push web
$ heroku container:release web

License

polls-api is released under the MIT license. See LICENSE.

polls-api's People

Contributors

abtris avatar dependabot[bot] avatar fosrias avatar honzajavorek avatar klokane avatar kylef avatar pksunkara avatar w-vi avatar zdne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polls-api's Issues

ValueError: No JSON object could be decoded

When POSTing invalid JSON to /questions, the app responds with 500. It should gracefully handle the error and to reply with 400 or 422.

Nov 21 22:06:26 pollsapi heroku/router: at=info method=POST path="/questions" host=polls.apiblueprint.org request_id=610b012b-630a-4e8b-8809-779cae39c19b fwd="204.40.194.136,162.158.63.154" dyno=web.1 connect=1ms service=82ms status=500 bytes=210 protocol=http 
Nov 21 22:06:26 pollsapi app/web.1: Internal Server Error: /questions 
Nov 21 22:06:26 pollsapi app/web.1: Traceback (most recent call last): 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner 
Nov 21 22:06:26 pollsapi app/web.1:     response = get_response(request) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response 
Nov 21 22:06:26 pollsapi app/web.1:     response = self._get_response(request) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response 
Nov 21 22:06:26 pollsapi app/web.1:     response = self.process_exception_by_middleware(e, request) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response 
Nov 21 22:06:26 pollsapi app/web.1:     response = wrapped_callback(request, *callback_args, **callback_kwargs) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view 
Nov 21 22:06:26 pollsapi app/web.1:     return self.dispatch(request, *args, **kwargs) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch 
Nov 21 22:06:26 pollsapi app/web.1:     return handler(request, *args, **kwargs) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/polls/views.py", line 133, in post 
Nov 21 22:06:26 pollsapi app/web.1:     body = json.loads(request.body) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/json/__init__.py", line 338, in loads 
Nov 21 22:06:26 pollsapi app/web.1:     return _default_decoder.decode(s) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/json/decoder.py", line 366, in decode 
Nov 21 22:06:26 pollsapi app/web.1:     obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
Nov 21 22:06:26 pollsapi app/web.1:   File "/app/.heroku/python/lib/python2.7/json/decoder.py", line 384, in raw_decode 
Nov 21 22:06:26 pollsapi app/web.1:     raise ValueError("No JSON object could be decoded") 
Nov 21 22:06:26 pollsapi app/web.1: ValueError: No JSON object could be decoded 

image

psycopg2 wheel package will be renamed from release 2.8

From logs, there is a warning regarding psycopg2 package will be renamed. We should consider updating to the renamed package.

May 15 11:30:43 pollsapi app/scheduler.6688: /usr/local/lib/python2.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. 
May 15 11:30:43 pollsapi app/scheduler.6688:   """) 
May 15 11:30:43 pollsapi app/scheduler.6688: Deleting 0 questions 

Siren form type is not filled

Siren form type is not filled. Most of clients will just fallback to "type": "application/x-www-form-urlencoded",, that the actual implementation will not accept.

Siren fields are not filled appropriately

As you can see from the image, actually Siren fields contains only the name property

image

It is great, but quite useless at the moment.
I think at least typeand title should be filled.

Enabling CORS header

Would be possible to enable CORS for this reference implementation?

This would be great to develop web applications on top of that.
Test case

Http batching

Would be possible to enable Http Batching of requests?

Support url template for pagination

The actual pagination returns hardcoded URLs. This mean that, in order to navigate to the page 5, I am forced to move thought all previous pages before I can get the final url.

Given that, jump directly to a particular page is not possible.

The API should offer, beyond those links, a templated one in order to compose it on the fly and jump to a particular page.

  "_links": {
    "post": {
      "href": "/posts{/id}",
      "templated": true
    }
  }

Pagination is missing "First" link

While the pagination provides a Last link, it is missing the First

Also, would be great if links could be ordered.

  1. First
  2. Prev
  3. Next
  4. Last

Reset mechanism for data

Actual backend for the api is completely polluted by tests made by the users time after time.
At this time, the question What is your favourite programming language is preset 87 times, making very difficult (and a bit boring as well) work on it.

I would suggest

  1. Provide more sample polls (one question is not enough. At least 5 would be good)
  2. While it would be great to keep polls results (the votes), I'd suggest to reset/remove all but default questions every hour, every day, or every-what-you-want

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.