npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

guarapi

v1.3.1

Published

Minimalist, fast, and scalable Node.js web http app framework

Downloads

20

Readme

Guarapi

Coverage Status npm version

Guarapi is a framework for building web applications with nodejs. It aims to provide a simple and elegant way to create fast and scalable web apps, without sacrificing functionality or performance. Guarapi offers a minimalist and expressive syntax, a flexible routing engine, and a rich set of built-in features. Guarapi is designed to be easy to learn, use, and extend, making it a great choice for beginners and experts alike.

Installation

npm i guarapi --save

Example

import guarapi, {
  middlewarePlugin,
  loggerPlugin,
  Router,
  MiddlewareError,
} from 'guarapi';

const app = guarapi();
const router = Router();

app.plugin(middlewarePlugin);
app.plugin(loggerPlugin);

router.get('/', (req, res) => {
  res.end('ok');
});

router.get('/respond-with-json', (req, res) => {
  res.json({ ok: true });
});

app.use(router);

app.use<MiddlewareError>((error, _req, res, _next) => {
  res.status((error as Error)?.message === 'Not Found' ? 404 : 500);
  res.json({ error: (error as Error)?.message || 'Internal Server Error' });
});

app.listen(3000, '0.0.0.0', () => {
  console.log('> Running: http://localhost:3000');
});

API Design

Guarapi adopts an elegant and intuitive API design approach, allowing developers to write clean and maintainable code. The framework's main handler provides pre, post, and error hooks for plugins, enabling you to efficiently manage various aspects of request handling.

  • pre Hook: This hook allows you to execute actions before the main request handler processes the request. It's useful for tasks like request validation or authentication checks.
  • post Hook: The post hook lets you perform actions after the main request handler has processed the request. You can use it for tasks such as response formatting or logging.
  • error Hook: When an error occurs during request processing, the error hook comes into play. It allows you to handle errors gracefully, whether by logging them or returning appropriate error responses.

Routing

Guarapi provides a flexible routing engine that simplifies the process of defining routes for your web application. With Guarapi's routing system, you can effortlessly handle various HTTP methods and URL patterns.

Route Parameters

Guarapi's routing system supports powerful route parameters, making it versatile for different use cases:

  • Basic Route Parameter: You can define simple route parameters using a colon notation, e.g., /user/:id. This notation allows you to capture dynamic values from the URL.
  • Wildcard Route Parameter: When a route parameter ends with a wildcard symbol (*), it captures the entire path as an array. For example, /profile/:path* captures all path segments as an array in req.params.path.
  • Pattern Matching: Guarapi also supports pattern matching in route parameters. For instance, /user/t(es)?t matches both tt and test.

Plugins

Guarapi comes equipped with a collection of built-in plugins, including middlewarePlugin and loggerPlugin, designed to simplify common development tasks and enhance the overall development experience. However, the extensibility of Guarapi goes beyond these built-in plugins.

You can create your custom plugins to extend the functionality of Guarapi. These plugins can handle various tasks such as observability, instrumentation, custom authentication, or any other specialized functionality tailored to your project's needs. The flexibility to create custom plugins empowers you to craft web applications that align precisely with your requirements.

License

Guarapi is open-source software licensed under the MIT License.

Contributing

We enthusiastically welcome contributions from the Guarapi community. If you're interested in contributing to the project, please follow the steps outlined in our Contribution Guidelines. Your contributions can include bug fixes, new features, documentation improvements, or any other enhancements that benefit the Guarapi framework.

Code of Conduct

To maintain a friendly and inclusive environment, we expect all contributors and community members to adhere to our Code of Conduct. This code sets the standard for respectful and collaborative interactions within the Guarapi community.

Feel free to explore the Guarapi documentation for more details on effectively and efficiently utilizing the framework in your projects. If you have any questions or require further assistance, don't hesitate to reach out to our vibrant and supportive community.

Happy coding with Guarapi!