
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@smarthost/feathers-unsplash
Advanced tools
FeathersJS service adapter for querying the Unsplash API
This project uses Feathers. An open source web framework for building modern real-time applications.
It is built on top of the official unsplash-js package.
This is a fork and update of marshallswain/feathers-unsplash
Below is a list of all exposed services and their implemented methods. All can be used like the UnsplashPhotos example given below
More documentation coming soon
npm install @smarthost/feathers-unsplash node-fetch unsplash-js
yarn add @smarthost/feathers-unsplash node-fetch unsplash-js
Other packages needed may be: tslib
, @feathersjs/errors
This adapter requires fetch
support, which means you'll need to provide it on the global scope. This means that somewhere in your app you need to use this code:
// preferably in the the index file
const fetch = require("node-fetch");
global.fetch = fetch;
// typescript
import fetch from "node-fetch";
global.fetch = fetch as any; // trick for type imcompatibility for now
First you'll need to setup Unsplash API access.
accessKey
into an environment variable.// default.json
"unsplash": {
"accessKey": "MYAPPNAME_UNSPLASH_ACCESS_KEY"
}
The easiest way to setup a service is to use the FeathersJS Cli to generate a "Custom Service". You can then delete the service-name.class.js
file that the generator makes and use code like in this example:
// Initializes the `unsplash-photos` service on path `/unsplash-photos`
const { UnsplashPhotos } = require("@smarthost/feathers-unsplash");
const hooks = require("./unsplash-photos.hooks");
module.exports = function (app) {
const options = {
accessKey: app.get("unsplash").accessKey,
};
// Initialize the service with any options it requires
app.use("/unsplash-photos", new UnsplashPhotos(options, app));
// Get the initialized service so that we can register hooks
const service = app.service("unsplash-photos");
service.hooks(hooks);
};
The find
method supports searching photos by the following query params:
keyword
: the search textorientation
: can be either portrait
or landscape
. Any other values return an empty list.collectionIds
: an array of collection ids.It also supports familiar pagination attributes: $limit
and $skip
. Note that since the Unsplash API only supports page-level pagination (not record-level skipping like most FeathersJS adapters), you must provide $skip
as a multiple of the $limit
. Here is an example query:
const response = await app.service('unsplash-photos').find({
query: {
$limit: 10, // this is the default limit
$skip: 10 // Skipping 10 returns the second page of data.
keyword: 'food',
orientation: 'portrait',
}
})
The get
method can be used in two ways:
id
to retrieve data about the image.'random'
to retrieve a random image. See possible params for photos.getRandomconst imageData = await app.service("unsplash-photos").get(id);
const randomImageData = await app.service("unsplash-photos").get("random");
For more information on all the things you can do with Feathers visit docs.feathersjs.com.
FAQs
Feathersjs wrapper for querying the unsplash api
The npm package @smarthost/feathers-unsplash receives a total of 0 weekly downloads. As such, @smarthost/feathers-unsplash popularity was classified as not popular.
We found that @smarthost/feathers-unsplash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.