https://github.com/jamesplease/api-pls-example
An api-pls example project
https://github.com/jamesplease/api-pls-example
api json-api rest-api
Last synced: 29 days ago
JSON representation
An api-pls example project
- Host: GitHub
- URL: https://github.com/jamesplease/api-pls-example
- Owner: jamesplease
- Created: 2017-02-05T02:35:20.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-22T01:20:00.000Z (about 8 years ago)
- Last Synced: 2025-02-07T09:42:00.926Z (3 months ago)
- Topics: api, json-api, rest-api
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# api-pls Example
This project demonstrates how to use [api-pls](https://github.com/jmeas/api-pls)
to start up an API webserver in any project.#### Prerequisites
- [Node.js](https://nodejs.org/en/) v7+
- a [PostgreSQL database](#how-can-i-start-a-postgresql-database-to-run-this-example)### Getting Started
Clone this repository. Then, install the dependencies:
```sh
npm install
```Next, create a file in the root of this project called `.env`. Add the following
line to the file, replacing the database URL with your own:```sh
DATABASE_URL='postgres://[email protected]:5432/example'
```Next, you'll need to create [Resource Models](https://github.com/jmeas/api-pls/wiki/Resource-Model).
These are the definitions that describe what tables and endpoints are created
for you.There are several examples already created for you in the `./resources` directory:
Review those, and make changes as you see fit.Once you're satisfied with your resource models, run `npm run sync`. This
will generate migrations from your models, and then apply them to the database.You're now ready to start the API webserver.
Run `npm run start` to get it running. Once it's up, navigate your browser to
`localhost:5000` to begin CRUD'ing.### FAQ
#### How can I change my resource models after the initial migration?
Eventually, api-pls will allow you to change your resources dynamically. It does
not support this now, however. If you change your resource models, you'll need
to clear all of the data in the database by running `npm run reset`.Once that completes, you can run `npm run sync` to bootstrap the database
with your updated models.#### How can I start a PostgreSQL database to run this example?
To run the example, you'll need a PostgreSQL database URL. It is recommended
that you create a database specifically for testing purposes, rather than
using a database that you are using for other uses, too.My preference is to create a free [Heroku](heroku.com) app, and then set up a
free version of
[Heroku's PostgreSQL add-on](https://elements.heroku.com/addons/heroku-postgresql).
This provides you with 10,000 rows and 20 connections for free: more than enough
than what you'll need to try out the example.You can also set up a database locally on your machine. This will differ
slightly between operating systems. I recommend searching
[StackOverflow](stackoverflow.com) for the best solution for your OS.#### My database does not use SSL; how can I connect to it?
You can set the "ssl" option to be `false` in your `.plsrc` file.
```json
{
"resourcesDirectory": "./resources",
"ssl": false
}
```