Skip to content

Latest commit

 

History

History
105 lines (76 loc) · 2.63 KB

README.md

File metadata and controls

105 lines (76 loc) · 2.63 KB

Petfinder JS SDK

CircleCI npm version Coverage Status

A JS wrapper for the Petfinder API, written in JavaScript/TypeScript.

Features

  • TypeScript definition
  • Promises (via Axios)
  • Well tested

Install

Using npm:

npm install --save @petfinder/petfinder-js

In browser:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/@petfinder/petfinder-js/dist/petfinder.min.js"></script>

Usage (Browser)

var pf = new petfinder.Client({apiKey: "my-api-key", secret: "my-api-secret"});

pf.animal.search()
    .then(function (response) {
        // Do something with `response.data.animals`
    })
    .catch(function (error) {
        // Handle the error
    });

Another way if you have issues with the above code snippet and using React

import { Client } from "@petfinder/petfinder-js";

const pf = new Client({
    apiKey: "my-api-key",
    secret: "my-api-secret",
  });

  const results = await pf.animal.search()
  console.log(results.data.animals)
};

Usage (Node/CommonJS)

var petfinder = require("@petfinder/petfinder-js");
var client = new petfinder.Client({apiKey: "my-api-key", secret: "my-api-secret"});

client.animal.search()
    .then(function (response) {
        // Do something with `response.data.animals`
    })
    .catch(function (error) {
        // Handle the error
    });

Usage (TypeScript/ES6 Module)

import { Client } from "@petfinder/petfinder-js";

const client = new Client({apiKey: "my-api-key", secret: "my-api-secret"});

client.animal.search()
    .then(function (response) {
        // Do something with `response.data.animals`
    })
    .catch(function (error) {
        // Handle the error
    });

If using primary_photo_cropped, some dogs or cats won't have images. I recommend adding a placeholder like below example if using React

<img
            src={
            animal.primary_photo_cropped
              ? animal.primary_photo_cropped.small
              : "https://source.unsplash.com/1600x900/?pets"
          }
          alt=""
        />

Documentation

See docs directory for more detailed documentation.