API-CLI
August 2024
This project was done during my time at Justworks. In an effort to understand APIs better and learn about command line interfaces, this project was created. The project has been further developed into an npm package that creates API endpoint & schema files and converts JSON objects to JSON schemas through the command line. All confidential information has been cleared by legal and approved for a personal project.
Why
In an approach to studying RESTful API endpoint structure and JSON schema
How
JavaScript
Project
Internship @ Justworks
Background
For my internship at Justworks, one of my projects was to create a command-line interface for API endpoint creation. The endpoint directory creation follows the structure of the API route and pre-populates the template as much as it can based on the interactive shell inputs from the user. This project was a chance for me to explore further about API endpoint creation, study RESTful APIs and schemas (response and request format), and learn about JSON schema format. This CLI has been registered into an npm package and has been integrated to API repositories within the company.
Core Features
Interactive File Creations
-
Create Endpoint Files Based on RESTful APIs
-
Generation of schema files (response.schema.js & body.schema.js)
JSON to JSON Schema
-
Converts JSON object to JSON Schema (referenced https://www.liquid-technologies.com/online-json-to-schema-converter)
-
Helps users to populate schema files
API Endpoint Creation
One can create an endpoint file interactively with a given prompt and with the given input from the user, it will automatically populate the template as much as it can. In case of when the user does specify to create a response file, it will automatically link to the correct response file on the first line of the endpoint file. ​
Schema Files Generation
1. Create Response Schema file (Body schema file is not asked for GET & DELETE)
2. Ask users if they want response and body schema files and prepends schema files if already exists
3. Result created
JSON to JSON Schema
You may have noticed the schema files being empty so apicli json command allows users to type in a JSON object and convert it to JSON schemas and simply paste it to the schema files that were created earlier. It is capable of handling simple JSON objects to complex and deeply nested JSON objects.
Further Capabilities
Conditional body.schema.js file
User will not be asked for creation of body.schema.js for GET or DELETE method as it doesn't have a request body.​
Pre-populate endpoint template
Schema, parameters, connected import response files, and routes are pre-populated.​
Purposeful error
Errors are purposefully triggered to prompt users to further customize
Strict Restriction
Prompts users to follow the strict rules of how APIs are composed when asking prompts (ex: directing users to put in routing format of /member & stops users from creating already existing endpoints).