Create your Serverless API in seconds with Apiker

npm version latest commit join our chat

Features

  • Easy routing & state management
  • Basic JWT-based Auth (register, login, refresh token, delete user)
  • Automatically updates Durable Object migrations, classes and bindings so you don't have to.
  • Get and set object state easily. e.g: await state().get(paramInCommonObj); or await state("MyObjectName").put({ myParam });
  • Rate Limiting
  • Firewall support (IP bans with Cloudflare Firewall)
  • Ability to send emails (with Sendinblue)
  • Simple Admin panel
  • User geolocation
  • Logging handlers

Install

To get started with your Apiker project, run:

npx apiker your-site-name

Note: If you haven't setup Wrangler yet, check out the "Development & Deployment" instructions below.

📦 Usage

Once your project is created, you can edit the app.toml and src/ files as desired :

Counter Example

src/index.js

controllers/counter.ts

> GET /users/test/counter

Demo: https://apiker-demo.volted.co/users/test/counter

Full example: Apiker Demo or npx apiker my-demo

🔐 Auth

When the authRoutes option is set to true, Apiker will register the following default routes:

/auth/register /auth/login /auth/refresh /auth/delete

> POST /auth/register

Request body:

Response (example):

Notes:

  • For auth implementation details, check out the source at Auth.ts

  • If you would like to implement your own auth, you can always copy the Auth.ts routes to your Apiker project and edit the authentication flow as needed.

  • ⚠️ Note: Auth routes are in active development. There might be significant changes in future versions. PRs and suggestions are always welcome!

🛡️ Firewall

Apiker can interact with the Cloudflare Firewall to prevent endpoint flooding.

To enable it, set the firewall option to true or pass an object such as the following:

The firewall option requires that you specify a Cloudflare Token with Firewall permissions in the .env. Please follow this guide on how to create API tokens.

Example (in your .env file):

Notes:

  • You can use the Firewall Banning and Unbanning handlers in your application at will. Just import the Firewall methods that are exported from the apiker package.

🚀 Development & Deployment

First time:

  • Install Cloudflare Wrangler
  • Edit your Apiker project's app.toml
  • wrangler login
  • npm run build
  • wrangler publish

On subsequent changes:

  • wrangler publish

⚠️ Note: Make sure you've read the Durable Object documentation if you need to install wrangler or have any doubts about app.toml (also known as wrangler.toml).

 Contributing

PRs and issues are always welcome. Feel free to submit any issues you have at: https://github.com/hodgef/apiker/issues