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

api-json-cli

v1.2.4

Published

CLI for creating API endpoint files

Downloads

5

Readme

Getting Started with API-CLI

This project is for creating API endpoint and schema files through the command line. One can customize the directory accordingly to where the files will be created. This CLI currently will create the files in the /routes directory (in the root) and when a user inputs a specific route will create corresponding files under the directory. For instance, if the user enters 'member' for directory when prompted, the files will be created under /routes/member. The API-CLI is built for the directory to follow the routing of the API for best practices.

How to run

Users can run apicli to see a little introduction of the cli. The command apicli --help will show an overview of what the cli is capable of.

Commands

There are currently two commands: apicli create and apicli json. To create an API-endpoint file, user will type in apicli create and prompted to the following prompts to create an API endpoint:

  1. User will be prompted to enter the route for the API endpoint.
  2. User will be prompted to select a RESTful method. If the selected method already exists in the given route, the CLI will exit.
  3. Depending on method (if not GET or DELETE) and if the schema files don't exist user will be asked if they would like to create the schema files (response.schema.js & body.schema.js).
  4. If the schema files exist but the user will like to create one they will have the option to do so. The new response files will be named http-method.response.schema.js, for instance, when the user selects post, the file name will be either post.response.schema.js \ post.body.schema.js. This is to prevent duplicate files and customizations could be further made on the index.js file. The import of the response schema file will be automatically setup to reflect the correct response file.

To create an JSON schema from a JSON object user will type in apicli json. The user will type in the json object they want to convert to a schema. It will able to discern objects and arrays within the given json schema. For date and date-time it will return the type to be "string" with format being either "date" or "date-time". It is currently capable of deeply nested JSON objects as well. Once the JSON schema is generated, the user can paste it to either the response.schema.js or body.schema.js file that was created from the previous steps. The JSON format currently follows the JSON to JSON Schema Converter.

Customization

The files are meant to trigger errors when first created by the CLI. Users will have to further customize the endpoint file where the @ is at which includes responseSchema, config permission, and Handler. The schema files and endpoint files for detailed coding is defaulted to be empty as the CLI will be more of providing the structure for initial building of the API endpoint.

NPM Package

This CLI is a npm package and could be installed as a dependency in any repository. Currently the API endpoint template is built to assist Fastify-CLI. Further customization on the template for API endpoint and schema files can be made on template.mjs and schemaTemplate.mjs. The routing or directory configuration can be made further as well.

Default Endpoint Template

import responseSchema from './response.schema.js';

/**  @type {import('fastify').FastifyPluginAsync} */
export default async function (fastify) {
  fastify.get('/routeName', {
    schema: {
      response: {
        200: responseSchema
      }
    },
    handler: @
  })
}


/** @type {import('fastify').RouteHandlerMethod} */
async function @Handler(request, reply) {
  throw {status: 501, message: 'Not implemented'}
}

Default Schema Template

export default { "type": "object", "properties": {} }