Skip to main content
The FrogBot Local API gives you the ability to execute the same operations that are available through REST and GraphQL within Node, directly on your server. Here, you don’t need to deal with server latency or network speed whatsoever and can interact directly with your database.
The Local API is incredibly powerful when used in React Server Components and other similar server-side contexts. With FrogBot, you don’t have to leave your server to gather the data you need. It can be incredibly fast and is definitely a game changer.
Here are some common examples of how you can use the Local API:
  • Fetching FrogBot data within React Server Components
  • Seeding data via Node seed scripts that you write and maintain
  • Opening custom Next.js route handlers which feature additional functionality but still rely on FrogBot
  • Within Access Control and Hooks

Accessing FrogBot

You can gain access to the currently running frogbot object via two ways:

Accessing from args or req

In most places within FrogBot itself, you can access frogbot directly from the arguments of Hooks, Access Control, validation functions, and similar. This is the simplest way to access FrogBot in most cases. Most config functions take the req (Request) object, which has FrogBot bound to it (req.frogbot). Example:

Importing it

If you want to import FrogBot in places where you don’t have the option to access it from function arguments or req, you can import it and initialize it.
getFrogBot accepts: getFrogBot caches the instance. Later calls with the same config return it and ignore these options. If you’re working in Next.js’ development mode, FrogBot will work with Hot Module Replacement (HMR), and as you make changes to your FrogBot Config, your usage of FrogBot will always be in sync with your changes. In production, getFrogBot simply disables all HMR functionality so you don’t need to write your code any differently. We handle optimization for you in production mode. If you are accessing FrogBot via function arguments or req.frogbot, HMR is automatically supported if you are using it within Next.js. For more information about using FrogBot outside of Next.js, click here.

Local options available

You can specify more options within the Local API vs. REST or GraphQL due to the server-only context that they are executed in. Every operation below accepts these options, except that auth operations and restoreVersion don’t accept select. Each operation below lists the options it adds.

Transactions

When your database uses transactions you need to thread req through to all local operations. Postgres uses transactions and MongoDB uses transactions when you are using replica sets. Passing req without transactions is still recommended.
By default, all access control checks are disabled in the Local API, but you can re-enable them if you’d like, as well as pass a specific user to run the operation with.

Collections

The following Collection operations are available through the Local API:

Create#collection-create

Accepts the common options plus:

Find#collection-find

Accepts the common options plus:
pagination, page, and limit are three related properties documented here.

Find by ID#collection-find-by-id

Accepts the common options plus:

Count#collection-count

Accepts the common options plus:

FindDistinct#collection-find-distinct

Accepts the common options plus:

Update by ID#collection-update-by-id

Accepts the common options plus:

Update Many#collection-update-many

Accepts the common options plus:

Delete#collection-delete

Accepts the common options plus:

Delete Many#collection-delete-many

Accepts the common options plus:

Duplicate#collection-duplicate

Accepts the common options plus: Fails when the collection sets disableDuplicate. Field beforeDuplicate hooks run on the copied data.

Versions

If a collection has Versions enabled, these operations are available:

Find Versions#collection-find-versions

Accepts the common options plus:

Find Version by ID#collection-find-version-by-id

Accepts the common options plus:

Count Versions#collection-count-versions

Accepts the common options plus:

Restore Version#collection-restore-version

Accepts the common options, except select, plus:

Auth Operations

If a collection has Authentication enabled, additional Local API operations will be available:

Auth

auth doesn’t accept the common options.

Login

Accepts the common options, except select, plus:

Forgot Password

Accepts the common options, except select, plus:

Reset Password

Accepts the common options, except select, plus:

Unlock

Accepts the common options, except select, plus:

Verify

Accepts the common options, except select, plus:

TypeScript

Local API calls will automatically infer your generated types. Here is an example of usage: