Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicolabovolato/basica
The Foundational Library of Modern Applications
https://github.com/nicolabovolato/basica
fastify framework javascript microservice microservices rest-api restful-api typebox typescript web-application
Last synced: 3 months ago
JSON representation
The Foundational Library of Modern Applications
- Host: GitHub
- URL: https://github.com/nicolabovolato/basica
- Owner: nicolabovolato
- License: mit
- Created: 2024-02-01T08:26:46.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-05-01T10:18:48.000Z (6 months ago)
- Last Synced: 2024-06-16T13:10:35.649Z (5 months ago)
- Topics: fastify, framework, javascript, microservice, microservices, rest-api, restful-api, typebox, typescript, web-application
- Language: TypeScript
- Homepage: https://basica.bovolato.dev
- Size: 641 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![CI](https://github.com/nicolabovolato/basica/actions/workflows/ci.yml/badge.svg)](https://github.com/nicolabovolato/basica/actions/workflows/ci.yml)
# Basica
The Foundational Library of Modern Applications
## [Docs](https://basica.bovolato.dev)
`npm install @basica/core @basica/config @basica/fastify`
```ts
import { IocContainer } from "@basica/core/ioc";
import { loggerFactory } from "@basica/core/logger";
import { AppBuilder } from "@basica/core";
import { configure, envProvider } from "@basica/config";import { lifecyclePlugin } from "@basica/fastify";
import { Type } from "@sinclair/typebox";
// Validate configuration
const config = configure(envProvider(), Type.Object({
logger: loggerConfigSchema
}));// Dependency injection
const container = new IocContainer()
.addSingleton("logger", () => loggerFactory(config.logger))
.addSingleton("svc", (s) => ({
hello: () => {
s.logger.info("svc called!");
return "hello world";
},
healthcheck: () => ({ status: "healthy" }),
}));const app = new AppBuilder(container)
// Lifecycle management
.configureLifecycle((b, c) => b
// Healthchecks
.addHealthcheck("svc", (c) => c.svc)
// Plugins
.with(lifecyclePlugin, (b) => b
.addFastifyEntrypoint("http", (f) => f
.mapHealthchecks({ path: "/health" })
.configureApp((app) => {
app
.useOpenapi()
.fastify.get("/", () => c.svc.hello());
}
)
)
)
).build();app.run();
```