0.22.6 ā€¢ Published 16 days ago

nixle v0.22.6

Weekly downloads
-
License
MIT
Repository
github
Last release
16 days ago

Overview

Nixle is a framework for building HTTP servers. It is designed to be simple, fast, and extensible. It is built on top of existing frameworks, such as Express, Fastify, and Nitro.

  • āœØ Simple and intuitive API.
  • šŸš€ Supports multiple providers such as Express, Fastify, and Hono.
  • šŸŒ Supports SSR frameworks such as Nuxt.
  • šŸ’Ŗ Incredible TypeScript support.
  • šŸŽÆ Easy to use and extend.

Documentation

You can find the documentation on the website.

Installation

npm install nixle

Usage

To set up your app, use the createApp function. Create a router with the createRouter function. Additionally, you can create services with module-specific logic using the createService function.

// usersRouter.ts
import { createRouter, createService } from 'nixle';

declare global {
  namespace Nixle {
    interface Env {
      USERS_SERVICE: string;
    }
  }
}

const usersService = createService('users', ({ log, env, ofetch }) => {
  const getUsers = async (limit: number) => {
    log.info('Getting users...');

    const users = await ofetch<{ name: string; email: string }[]>(`${env.USERS_SERVICE}/users`);

    log.success(`Got ${users.length} users`);

    return users;
  };

  return {
    getUsers,
  };
});

export const usersRouter = createRouter('/users', ({ route, zodObject }) => [
  route.get('/', {
    queryValidation: zodObject({
      limit: zod.number().default(10),
    }).validate,
    handler: ({ query }) => {
      return usersService().getUsers(query.limit);
    },
  }),
]);

Providers

We have several providers that you can use to create your app such as Nuxt, Express, Fastify, and Elysia (Bun). Choose the one that suits you best and install packages for it. More information about providers can be found in the docs.

For example, if you want to use Fastify, install the @nixle/fastify package besides the nixle package:

npm install @nixle/fastify

Then, import the fastifyProvider function and pass it to the createApp function:

import fastify from 'fastify';
import { createApp } from 'nixle';
import { fastifyProvider } from '@nixle/fastify';
import { zodPlugin } from '@nixle/zod';
import { ofetchPlugin } from '@nixle/ofetch';
import { usersRouter } from './usersRouter';

const { app, $inferRouters } = createApp({
  provider: fastifyProvider(fastify()),
  router: [usersRouter],
  plugins: [zodPlugin, ofetchPlugin()],
});

app.listen({ port: 4000 });

type NixleRouters = typeof $inferRouters;
// {
//   '/users': {
//     '/': {
//       GET: {
//         query: {
//           limit: number;
//         };
//         response: { name: string; email: string }[]
//       }
//     }
//   };
// }

Author

Ā© letstri, released under the MIT license.

0.22.6

16 days ago

0.22.5

16 days ago

0.22.4

16 days ago

0.22.2

16 days ago

0.22.1

16 days ago

0.22.0

16 days ago

0.21.2

21 days ago

0.21.1

22 days ago

0.21.0

22 days ago

0.20.8

2 months ago

0.20.7

2 months ago

0.20.6

2 months ago

0.20.5

2 months ago

0.20.4

2 months ago

0.20.3

2 months ago

0.20.2

2 months ago

0.20.1

2 months ago

0.20.0

2 months ago

0.19.6

2 months ago

0.19.5

2 months ago

0.19.0

2 months ago

0.19.1

2 months ago

0.19.2

2 months ago

0.19.3

2 months ago

0.19.4

2 months ago

0.18.3

3 months ago

0.18.2

3 months ago

0.17.12

3 months ago

0.17.11

3 months ago

0.17.14

3 months ago

0.17.13

3 months ago

0.18.1

3 months ago

0.18.0

3 months ago

0.17.10

4 months ago

0.17.9

4 months ago

0.17.6

4 months ago

0.17.7

4 months ago

0.17.8

4 months ago

0.17.5

4 months ago

0.17.4

4 months ago

0.17.2

4 months ago

0.17.3

4 months ago

0.17.0

4 months ago

0.17.1

4 months ago

0.16.12

4 months ago

0.16.13

4 months ago

0.16.10

4 months ago

0.16.11

4 months ago

0.16.6

4 months ago

0.16.7

4 months ago

0.16.9

4 months ago

0.16.3

4 months ago

0.16.4

4 months ago

0.16.5

4 months ago

0.16.1

4 months ago

0.16.2

4 months ago

0.16.0

4 months ago

0.15.3

5 months ago

0.15.0

5 months ago

0.15.1

5 months ago

0.13.3

5 months ago

0.15.2

5 months ago

0.13.4

5 months ago

0.14.0

5 months ago

0.13.0

5 months ago

0.13.1

5 months ago

0.13.2

5 months ago

0.12.10

5 months ago

0.12.11

5 months ago

0.12.12

5 months ago

0.12.7

5 months ago

0.12.8

5 months ago

0.12.9

5 months ago

0.12.0

5 months ago

0.12.1

5 months ago

0.12.2

5 months ago

0.12.3

5 months ago

0.12.4

5 months ago

0.12.5

5 months ago

0.12.6

5 months ago

0.11.1

5 months ago

0.11.2

5 months ago

0.11.0

5 months ago

0.10.14

5 months ago

0.10.15

5 months ago

0.10.12

5 months ago

0.10.13

5 months ago

0.10.11

5 months ago

0.10.9

5 months ago

0.10.1

5 months ago

0.10.2

5 months ago

0.10.3

5 months ago

0.10.4

5 months ago

0.10.10

5 months ago

0.10.5

5 months ago

0.10.6

5 months ago

0.10.7

5 months ago

0.10.8

5 months ago

0.10.0

5 months ago

0.9.1

5 months ago

0.9.0

5 months ago

0.8.2

5 months ago

0.8.1

5 months ago

0.8.0

5 months ago

0.7.4

5 months ago

0.7.3

5 months ago

0.7.2

5 months ago

0.7.1

5 months ago

0.7.0

5 months ago

0.6.1

5 months ago

0.6.0

5 months ago

0.5.1

5 months ago

0.5.0

5 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.4.0

5 months ago

0.3.0

5 months ago

0.2.11

5 months ago

0.2.10

5 months ago

0.2.9

5 months ago

0.2.8

5 months ago

0.2.7

5 months ago

0.2.6

5 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago