Giter Club home page Giter Club logo

pyp-starwars-api's Introduction

[pyp-w2] Star Wars API

Star Wars

Today we will implement a client for the Star Wars API: https://swapi.co/ (a.k.a. swapi). See extra documentation about the API here: https://swapi.co/documentation

swapi is using a RESTful structure. It has well defined "groups" of data, also known as resources (ie: people, planets, starships, etc). Each resource has its own URL path. There are URLs used for LISTing many objects of given resource (ie: /api/people/), and other for getting the details of one particular object of the resource (ie: /api/people/1/).

We will concentrate in two particular resources: People and Films. For each of them, we will need to create a model class able to query and present the data. You must respect the following interface:

>>> luke = People.get(1)
>>> str(luke)
"Person: Luke Skywalker"
>>> luke.name
"Luke Skywalker"
>>> luke.birth_year
"19 BBY"

Resources must also implement a way of iterating through all objects. To do that, we will use the all() classmethod, which will return a QuerySet iterable object:

>>> qs = People.all()
>>> next(qs)
"Person: Luke Skywalker"
>>> next(qs)
"Person: C-3PO"

Iterative structures like for, while and list comprehensions must also be supported by QuerySets:

>>> len([person for person in People.all()])
87
>>> for person in People.all():
        print(person.name)
"Luke Skywalker"
"C-3PO"
...

QuerySets must implement an easy way of returning the amount of objects it contains:

>>> qs.count()
87

Feel free to expand the client behavior with extra functionality.

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.