Code Monkey home page Code Monkey logo

swapi_lib's Introduction

SWAPI_LIB

Library/Wrapper for https://swapi.co

Getting Started:

There are five categories of functions in this library, acoording to the API resources: People, Films, Starships, Vehicles, Species and Planets. Each category has 2 functions e.g. for Planets they are:

-> getPlanets(id): e.g. getPlanets(1), getPlanets([1,2,3]), getPlanets()
-> getPlanetsSchema()

The first function getPlanets() accepts three variations of inputs:

-> 0 inputs: `getPlanets()` returns information on all the available Planets;
-> 1 input: 
- 1 id: `getPlanets(1)` returns information about the 1st Planet, if there is one
- array of ids: `getPlanets([1,2,6])` returns information about the 1st, 2nd and 6th Planet, if they exist

If some Planet if queried and does not exist, the error "404 Not found" will still be appended to the returned object.

Additionally there is a function getResources() to provide information on all available resources within the API.

Every function implemented in the SWAPI_LIB deals with promises (https://developer.mozilla.org/pt-PT/docs/Web/JavaScript/Reference/Global_Objects/Promise).

Example of usage:

swapiLib.Vehicles.getVehicles([1,2,3])
	.then(function (response) {
			//Do Stuff
		})
	.catch(function (error) {
			//Deal with error. E.g. having too many inputs to function
});

NOTE: Tested in Firefox 53.0.2, Chrome 58.0.3029.110 and Opera 45.0.

swapi_lib's People

Contributors

jmales 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.