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

crudi

v0.2.0

Published

Crudi is a tool for quickly generating HTTP routes that perform basic CRUD operations for your HAPI project. It's a useful tool for quickly building out a restful API for protyping or simple production projects.

Downloads

19

Readme

crudi

Crudi is a tool for quickly generating HTTP routes that perform basic CRUD operations for your HAPI project. It's a useful tool for quickly building out a restful API for protyping or simple production projects.

Tutorial

A more detailed tutorial is coming soon, the following is just a quick start.

1. Create a domain object

Use the Domain.build function to create an instance of a DomainModel object to define your model. The build method accepts 2 parameters: name and fields. The name parameter is a string that defines the name of your model and determines the name of the collection that they will be stored in. The fields parameter is an array of field definitions. There are 3 ways to define a field:

  1. Pass only the field name - Passing just a string as the field definition creates a field using all default settings using the passed string as the name of the field. The default settings for v.0.0.6 are type string and required true.
  2. Pass an object defining the fields properties - Passing an object will allow more control over the field. You can set the name, type, requirement, description, and validator. The available types are 'array','date','number', and 'string'. If needed, you can pass a custom Joi validator in the validator property rather than allow Crudi to generate it for you.
  3. Pass an instance of a DomainField - In future versions, this will allow deeper customization. At the moment, it's just something that you can do if you feel like it.

Example The following creates a Crudi domain you can use to generate a Crudi service

var Crudi = require('crudi');

var projectDomain = Crudi.Domain.build(
{
    name:'project',
    fields: [
        'teamName',
        'projectName',
        {name:'teamMembers', type:'array'},
        {name: 'office', type: 'array'},
        'description',
        'targetAudience',
        'youtubeId',
        {name:'additionalUrl', required: false},
        {name:'notes', required:false},
        {name:'createDate', type:'date'}
    ]
});

module.exports = projectDomain;

2. Add a Crudi service to Hapi using your domain object

To add the service routes for your domain to Hapi, create your Hapi server normally, then call the Crudi.AddService method passing your domain object and the Hapi server instance. This will register the CRUD routes with Hapi.

Example The below example creates and instance of Hapi, with Swagger documetation, using the ProjectDomain defined in the previous example.

var Hapi =      require('hapi'),
	Inert =         require('inert'),
	Vision =        require('vision'),
	HapiSwagger =   require('hapi-swagger'),
	Pack =          require('./package'),
	Crudi =         require('crudi'),
	ProjectDomain = require('.project_domain'),
	Joi =           require('joi');


var server = new Hapi.Server(),
    swaggerOptions = {
        'info': {
            'title': 'My API',
            'version': Pack.version
        }
    };


function startServer() {
    server.connection({port: 1337, routes : {cors:true}});

    Crudi.AddService(ProjectDomain, server);


    server.register([
        Inert,
        Vision,
        {
            'register': HapiSwagger,
            'options' : swaggerOptions
        }
    ], function(err){
        if(err){
            console.log(err);
            throw err;
        }
        server.start(function(err){
            if(err){
                console.log(err);
                throw err;
            }

            console.log('Server running at:' + server.info.uri);
        })
    });
};

startServer();

I know this documentation is pretty sparse. More details, as well as an example service, will be added in the coming weeks.