Disclaimer: This application is currently in Beta mode and is not ready for production. Please use at your own risk as things will change almost daily.
The following examples can be found in this project template.
- CRUD routes for a single resource
- A Knex model providing CRUD methods for DB operations
- Some route tests with mocks on the database calls
- Okta authentication verification middleware
- eslint setup and prettier formating.
- Jest coverage setup
- Inline Swagger docs with a live route at
/api-docs - Github workflow config setup to run linting, tests and upload coverage to code climate
- docker-compose file for spinning up postgresql db. (Win10 Home requires WSL)
All Labs Engineering Standards must be followed.
All routes can be viewed in the /api-docs route of your deploy (or locally).
Swagger docs are created using open api v3 notations. The docs are found inline
on the router files in api/**/*Router.js and use the yaml notation format.
The root of the docs is in config/jsdoc.js using the json format.
The following libraries have been used to build and serve the swagger docs live.
PORT- API port (optional, but helpful with FE running as well)DS_API_URL- URL to a data science api. (eg. https://ds-bw-test.herokuapp.com/)DS_API_TOKEN- authorization header token for data science api (eg. SUPERSECRET)DATABASE_URL- connection string for postgres databaseOKTA_URL_ISSUER- The complete issuer URL for verifying okta access tokens.https://example.okta.com/oauth2/defaultOKTA_CLIENT_ID- the okta client ID.
See .env.sample for example values
There are 3 options to get postgresql installed locally [Choose one]:
- Use docker. Install for your platform
- run:
docker-compose up -dto start up the postgresql database and pgadmin. - Open a browser to pgadmin and you should see the Dev server already defined.
- If you need to start over you will need to delete the folder
$ rm -rf ./data/pgas this is where all of the server data is stored.- if the database
api-devwas not created then start over.
- if the database
- run:
- Download and install postgresql directly from the main site
- make note of the port, username and password you use to setup the database.
- Connect your client to the server manually using the values previously mentioned
- You will need to create a database manually using a client.
- Make sure to update the DATABASE_URL connection string with the values for username/password, databasename and server port (if not 5432).
- Setup a free account at ElephantSQL
- Sign up for a free
Tiney Turtleplan - copy the URL to the DATABASE_URL .env variable
- make sure to add
?ssl=trueto the end of this url
- Sign up for a free
-
For Labs projects, clone the repo. Otherwise you can create a new repo using this as a template.
-
note please be sure to set your remote for this repo to point to your Labs Team Repository.
-
Alternatively you can clone this repo then remove the git folder to initialize a new repo
> git clone --depth=1 --branch=main [email protected]:Lambda-School-Labs/labs-api-starter.git NEW-REPO-NAME > rm -rf ./NEW-REPO-NAME/.git
-
-
run:
npm installto download all dependencies. -
run:
cp .env.sample .envand update the enviornment variables to match your local setup. -
run:
npm run knex migrate:latestto create the starting schema. -
run:
npm run knex seed:runto populate your db with some data. -
run:
npm run teststo confirm all is setup and tests pass. -
run:
npm run watch:devto start nodemon in local dev enviornment.
Make sure to update the details of the app name, description and version in the
package.jsonandconfig/jsdoc.jsfiles.
ESLint and prettier are already configured with Lambda Labs standards and ready to go. These must be ran from the CLI prior to commiting code in the following ways:
npm run lintto view all purposed fixes.npm run lint:fixto apply fixes to eslint issues.npm run formatto apply the standards defined by eslint/prettier config.
Alternatively you can install plugins for your editor of choice.