npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular2-swapi

v0.0.2

Published

Angular2Swapi library will help developers building angular and ionic applications which are using data from **StarWars API**.

Downloads

10

Readme

angular2-swapi

Angular2Swapi library will help developers building angular and ionic applications which are using data from StarWars API.

angular swapi

Installation

To install this library run:

npm install angular2-swapi --save

Bootstrap

Import Angular2SwapiModule in your app.module.ts file and add it into imports array:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { Angular2SwapiModule } from 'angular2-swapi';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    Angular2SwapiModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Angular2SwapiService

angular2-swapi is actually service library providing methods to call https://swapi.co and return resources based on your query. You can say it is HTTP client for StarWars API.

List of available methods

People

Method | Parameters | Return | Description -------|------------|--------|------------ getPeople() | page?: number | Observable<People[]> | Returns list of people as Observable getPeopleById(id) | id: number | Observable< People > | Returns character by id searchPeople(name) | name: string | Observable<People[]> | Search people by name

Films

Method | Parameters | Return | Description -------|------------|--------|------------ getFilms() | page?: number | Observable<Film[]> | Returns list of films as Observable getFilm(id) | id: number | Observable < Film > | Returns film by id searchFilms(title) | title: string | Observable<Film[]> | Search films by title

Starships

Method | Parameters | Return | Description -------|------------|--------|------------ getStarships(page) | page?: number | Observable<Starship[]> | Return list of starships as Observable getStarship(id) | id: number | Observable< Starship > | Return starship by id searchStarships(name) | name: string | Observable<Starship[]> | Search starships by name or model

Vehicles

Method | Parameters | Return | Description -------|------------|--------|------------ getVehicles(page) | page?: number | Observable<Vehicle[]> | Return list of vehicles as Observable getVehicle(id) | id: number | Observable< Vehicle > | Returns vehicle by id searchVehicles(name) | name: string | Observable<Vehicle[]> | Search vehicles by name or model

Species

Method | Parameters | Return | Description -------|------------|--------|------------ getSpecies(page) | page?: number | Observable<Species[]> | Return list of species as Observable getSpeciesById(id) | id: number | Observable< Species > | Returns species by id searchSpecies(name) | name: string | Observable<Species[]> | Search species by name

Planets

Method | Parameters | Return | Description -------|------------|--------|------------ getPlanets(page) | page?: number | Observable<Planet[]> | Return list of planets as Observable getPlanet(id) | id: number | Observable< Planet > | Returns planet by id searchPlanets(name) | name: string | Observable<Planet[]> | Search planets by name

Using Angular2SwapiService

Get list of films and display data:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Angular2SwapiService, Film } from 'angular2-swapi';

@Component({
  selector: 'app-root',
  template: `
    <li *ngFor="let film of film$ | async">
      <h1>{{ film.title }}</h1>
      <h3>{{ film.release_date | date }}</h3>
      <p>{{ film.opening_crawl }}</p>
    </li>
  `,
  styles: []
})
export class AppComponent implements OnInit {

  film$: Observable<Film[]>;

  constructor(private _swapi: Angular2SwapiService) {}

  ngOnInit() {
    // Get list of films you can specify page
   this.film$ = this._swapi.getFilms();
  }

}

Search films by title:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Angular2SwapiService, Film } from 'angular2-swapi';

@Component({
  selector: 'app-root',
  template: `
    <li *ngFor="let film of film$ | async">
      <h1>{{ film.title }}</h1>
      <h3>{{ film.release_date | date }}</h3>
      <p>{{ film.opening_crawl }}</p>
    </li>
  `,
  styles: []
})
export class AppComponent implements OnInit {

  film$: Observable<Film[]>;

  constructor(private _swapi: Angular2SwapiService) {}

  ngOnInit() {
    // Search films by title
   this.film$ = this._swapi.searchFilms('menace');
  }

}

Get film by id:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Angular2SwapiService, Film } from 'angular2-swapi';

@Component({
  selector: 'app-root',
  template: `
    <li *ngIf="film$ | async as film">
      <h1>{{ film.title }}</h1>
      <h3>{{ film.release_date | date }}</h3>
      <p>{{ film.opening_crawl }}</p>
    </li>
  `,
  styles: []
})
export class AppComponent implements OnInit {

  film$: Observable<Film>;

  constructor(private _swapi: Angular2SwapiService) {}

  ngOnInit() {
    // Get film with id=2
   this.film$ = this._swapi.getFilm(2);
  }

}

You can use the same pattern to get all the other resources from Star Wars API and display them in your application.

Where is Wookiee?

I don't speak wookie, do you? Still working on it.

StarWars API Resources

Please check full Star Wars API documentation by Paul Hallet at https://swapi.co/documentation