Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixelhandler/blog-api
JSON API following jsonapi.org spec for a blog application with auth for creating and editing post resources
https://github.com/pixelhandler/blog-api
Last synced: 8 days ago
JSON representation
JSON API following jsonapi.org spec for a blog application with auth for creating and editing post resources
- Host: GitHub
- URL: https://github.com/pixelhandler/blog-api
- Owner: pixelhandler
- Created: 2015-05-02T17:53:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T01:30:02.000Z (over 1 year ago)
- Last Synced: 2024-10-30T12:25:31.863Z (about 2 months ago)
- Language: PLpgSQL
- Size: 639 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Blog API
JSON API following [jsonapi.org] spec for a blog application with auth for creating and editing post resources
* .ruby-version is setup for 3.0.6
* Serialization of models (to JSON) is done with the [jsonapi-resources] gem
* Use ActiveRecord and the `pg` gem for [PostgreSQL]## Setup
* `bundle` to install the gems
* `mkdir -p shared/log && mkdir -p shared/pids && mkdir -p shared/sockets`### Config
Copy the config/database.example.yml config/secrets.example.yml files to:
config/database.yml config/secrets.ymlIn the database.example.yml file the password is set to and environemnt variables:
BLOG_API_DB_USR and BLOG_API_DB_PWORD. set your environment variables, or replace them
with your db credentialsexport BLOG_API_DB_USR='blog_api'
export BLOG_API_DB_PWORD='XXXX'* DB role 'blog_api'
Setup a Postgress role: 'blog_api'
createuser -P -s -e blog_api
createdb blog_api_development -O blog_apiOr,
PGUSER=$BLOG_API_DB_USR PGPASSWORD=$BLOG_API_DB_PWORD psql -h localhost -p 5432 blog_api_development
CREATE ROLE blog_api WITH SUPERUSER LOGIN PASSWORD 'X';
CREATE DATABASE blog_api_development OWNER blog_api;
CREATE DATABASE blog_api_test OWNER blog_api;* `bundle exec rake db:setup`
* See the seeds file to create resources for a post, author, and user### Seeds
Copy the db/seeds.example.rb and add records for an user, author and posts
## Restore DB from production
1) Use tunnel
ssh -fNg -L 54321:127.0.0.1:5432 pixelhandler.com
lsof -i tcp | grep ^ssh2) Dump database (use pword from prod)
current_time=$(date "+%Y.%m.%d-%H.%M.%S"); pg_dump -U $BLOG_API_DB_PROD_USR -h localhost -p 54321 $BLOG_API_DB_PROD > $BLOG_API_DB_PROD"."$current_time".sql"
3) Drop and create
bin/rails db:drop
bin/rails db:create4) Import
PGUSER=$BLOG_API_DB_USR PGPASSWORD=$BLOG_API_DB_PWORD psql -h localhost -p $BLOG_API_DB_PORT blog_api_development < blog_api_production.sql
## Docker For PostgreSQL
- https://docs.docker.com/engine/examples/postgresql_service/#installing-postgresql-on-docker
docker build -t eg_postgresql .
docker run --rm -P --name pg_test eg_postgresql
docker ps
psql -h localhost -p 32768 -d docker -U docker --password`docker` is the pword.
## Notes / Reference
* Slugs:
* Token Auth:
*
*[jsonapi.org]: http://jsonapi.org
[PostgreSQL]: http://www.postgresql.org
[jsonapi-resources]: https://github.com/cerebris/jsonapi-resources