Giter Club home page Giter Club logo

barker-api's Introduction

Barker API

Twitter for Dogs!

This is a node.js express API that I built to create, play around with, and demo a micro-front end application. Barker is Twitter for dogs because dogs love tweets and microfrontends.


I used my node-jwt-sqlite-starter template to start this project so it uses JWT for authentication. For now it uses a SQLite DB that runs locally in memory. I don't have it hosted at this time since it's just been for demo/experimental/dev purposes.
Check out this blog post I wrote about that starter template to understand how auth, sqlite, and other features are set up in this project.

Get Started

1. Install Node Packages

npm install

2. Environment Variables.

You will need a .env file with variables for: SESSION_SECRET, APP_SECRET, and DB_HOST.

Your secret strings can be anything and to get this running locally without a hosted db you can have :memory: for your DB_HOST value.

2. Run the Project

npm run start

or

npm run debug

3. Seed Data

If you look at repositories/dao.js you will see a static method called setupDbForDev. I built this to insert seed data into the Users, Posts, and Comments table so you can get started right away.

This function is invoked in the main app.js file when the initial project is run. If you host your DB, remove this call from that file so it doesn't run every time. I built this to run locally for demo purposes so I keep it in that file for now to run each time to insert seed data.

3. Authentication

In the seed data above, there were a few users added. You can pick one of these users and the password "123" to authenticate. Bcrypt is used to hash passwords in case you decide to allow users to create accounts later. For now, "123" is the password for the 6 seed accounts.

NOTE: "123" is not a safe password to use. This is for development/experimental purposes only.

To authenticate, send a POST request to localhost:3000/api/users/login with a request body:

{"username": "banjo", "password": "123"}

and this will get you an access-token for future requests.

After that, add an access-token header to future requests with the value you recieved in the /api/users/login POST response.

4. Access Data

With a valid access-token header from the step above, you can now access other routes in this API.

To test, try a GET request to localhost:3000/api/users/2. You should get some user data from on of my dogs, Kahlo.

barker-api's People

Contributors

mwolfhoffman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.