Socket
Book a DemoInstallSign in
Socket

api-pls

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-pls

Effortless JSON API-compliant APIs

0.9.0
Source
npmnpm
Version published
Weekly downloads
18
80%
Maintainers
1
Weekly downloads
 
Created
Source

api-pls

Travis build status

api-pls enables you to effortlessly create JSON API-compliant APIs.

Note: this project is a work in progress. It currently functions in a limited manner.

Motivation

It can be time-consuming to put together an application with a robust backend. Use api-pls to speed up that process considerably.

Instead of writing database and API code within your project, simply define models, and let this tool do the rest.

api-pls will:

✓ Configure a database for you
✓ Set up a web server that adheres to JSON API for interactions with those resources
Create and run migrations for you when you change your resource models

This project is a work in progress. Resource migrations beyond the initial set up are currently unsupported.

Technologies Used

Currently, the only supported database is PostgreSQL. The webserver is written in Node.js using Express.

Getting Started

Try out the example project to see api-pls in action.

Installation

api-pls is a CLI tool. Install it into your project using npm.

npm install api-pls --save

The name of the CLI program is pls. The rest of this guide assumes that pls is on your path. If you've installed it locally into a project, then you will need to call it from within an npm script.

Basic Usage

Create a file in the root of your project called .env. Add the following line to the file, replacing the database URL with your own:

DATABASE_URL='postgres://user@example.com:5432/example'

Next, you'll need to create resource models. These are the definitions that describe what tables and endpoints are created for you. Place your resource models in the directory ./resources.

More complete documentation for the resource model files is coming soon; for now, refer to the example project.

Once you've defined your resources, run pls migrate. This will generate database migrations from your resource models, and then run those migrations.

You're now ready to start an API webserver. Run pls start to start the server.

You can access the API webserver at localhost:5000.

Anytime you make changes to your resource models, be sure to run pls reset-database to clear out all of the previous models. Presently, only the initial migrations are supported.

CLI

CommandDescription
reset-databaseRemoves all tables from the database
migrateBuilds, then applies, migrations
startStarts up the API webserver.

CLI Flags

All of the options may also be specified in .plsrc, if you would prefer.

FlagsDefaultDescription
-h, --helpN/AView all the commands from the command line
-v, --versionN/ADisplay the version of api-pls
-d, --databaseSpecify the database URL
-p, --port5000Configure the port of the webserver
-r, --resources./resourcesSet the directory of your resources
-s, --ssltrueWhether or not to connect to the DB with SSL
--silentDisable logging
--verboseEnable verbose logging

Example CLI Usage

The following example turns off SSL, sets the port to be 6000, and sets the resource directory.

pls start -p 6000 -s false -r ./my-resources

Acknowledgements

Many thanks goes to Tyler Kellen for his work on Endpoints (which inspired me to write this) and for our many conversations about REST.

Keywords

json-api

FAQs

Package last updated on 05 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.