The Local Logic Client library provides a JavaScript entry point to Local Logic Scores, Points of Interest, Demographics, Schools, Profiles, and Geographies.
Npm:
npm install @local-logic/client
Yarn:
yarn add @local-logic/client
Pnpm:
pnpm add @local-logic/client
To use the library, start by creating a new instance by invoking LocalLogicClient
with your apiKey
. You can generate a apiKey using the locallogic.co/oauth/apiKey
API.
Example:
import LocalLogicClient, { Scores } from "@local-logic/client";
...
const client = LocalLogicClient("<apiKey>");
let scores: Scores | undefined;
try {
scores = await client.getScores({
lat: 45.532970,
lng: -73.585600,
include: ["groceries"]
});
} catch (e) {
// Handle error
}
You can catch errors by wrapping your method invokations in try / catch
. You can handle your errors generically, or if you require more granular control you can make use of the provided typeguards isRequestError
and isValidationError
.
Example:
import LocalLogicClient, {
isRequestError,
isValidationError,
} from "@local-logic/client";
try {
// Call method
} catch (e) {
if (isRequestError(e)) {
// Handle request errors
}
if (isValidationError(e)) {
// Handle validation errors
}
// Handle all other errors
}
@local-logic/client
provides type definitions and typeguards.