Giter VIP home page Giter VIP logo

ah-backend-iroquois's Introduction

Build Status Coverage Status Maintainability

Authors Haven - A Social platform for the creative at heart.

Vision

Create a community of like minded authors to foster inspiration and innovation by leveraging the modern web.


API Spec

The preferred JSON object to be returned by the API should be structured as follows:

Users (for authentication)

{
  "user": {
    "email": "[email protected]",
    "token": "jwt.token.here",
    "username": "jake",
    "bio": "I work at statefarm",
    "image": null
  }
}

Profile

{
  "profile": {
    "username": "jake",
    "bio": "I work at statefarm",
    "image": "image-link",
    "following": false
  }
}

List of Users with their profiles

{
  "users": [
    {
      "email": "[email protected]",
      "username": "jake",
      "profile": {
        "username": "jake",
        "bio": "I work at statefarm",
        "image": "image-link",
        "following": false
      }
  },
  {
    "email": "[email protected]",
      "username": "jake2",
      "profile": {
        "username": "jake2",
        "bio": "I work at statefarm2",
        "image": "image-link2",
        "following": false
      }
  }
  ]
}

Single Article

{
  "article": {
    "slug": "how-to-train-your-dragon",
    "title": "How to train your dragon",
    "description": "Ever wonder how?",
    "body": "It takes a Jacobian",
    "tagList": ["dragons", "training"],
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:48:35.824Z",
    "favorited": false,
    "favoritesCount": 0,
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }
}

Multiple Articles

{
  "articles":[{
    "slug": "how-to-train-your-dragon",
    "title": "How to train your dragon",
    "description": "Ever wonder how?",
    "body": "It takes a Jacobian",
    "tagList": ["dragons", "training"],
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:48:35.824Z",
    "favorited": false,
    "favoritesCount": 0,
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }, {

    "slug": "how-to-train-your-dragon-2",
    "title": "How to train your dragon 2",
    "description": "So toothless",
    "body": "It a dragon",
    "tagList": ["dragons", "training"],
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:48:35.824Z",
    "favorited": false,
    "favoritesCount": 0,
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }],
  "articlesCount": 2
}

Single Comment

{
  "comment": {
    "id": 1,
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:22:56.637Z",
    "body": "It takes a Jacobian",
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }
}

Multiple Comments

{
  "comments": [{
    "id": 1,
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:22:56.637Z",
    "body": "It takes a Jacobian",
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }],
  "commentsCount": 1
}

List of Tags

{
  "tags": [
    {
      "id": 1,
      "tag_name": "reactjs"
    },
    {
      "id": 2,
      "tag_name": "angularjs"
    }
  ]
}

List of reports

{
  "reports": [
    "user": "jake",
    "article": "how-to-train-your-dragon",
    "report_message": "let me report this issue"
  ]
}

Errors and Status Codes

If a request fails any validations, expect errors in the following format:

{
  "errors":{
    "body": [
      "can't be empty"
    ]
  }
}

Other status codes:

401 for Unauthorized requests, when a request requires authentication but it isn't provided

403 for Forbidden requests, when a request may be valid but the user doesn't have permissions to perform the action

404 for Not found requests, when a resource can't be found to fulfill the request

Endpoints:

Authentication:

POST /api/users/login

Example request body:

{
  "user":{
    "email": "[email protected]",
    "password": "jakejake"
  }
}

No authentication required, returns a User

Required fields: emailpassword

Registration:

POST /api/users

Example request body:

{
  "user":{
    "username": "Jacob",
    "email": "[email protected]",
    "password": "jakejake"
  }
}

No authentication required, returns a User

Required fields: emailusernamepassword

Get Current User

GET /api/user

Authentication required, returns a User that's the current user

Update User

PUT /api/user

Example request body:

{
  "user":{
    "email": "[email protected]",
    "bio": "I like to skateboard",
    "image": "https://i.stack.imgur.com/xHWG8.jpg"
  }
}

Authentication required, returns the User

Accepted fields: emailusernamepassword

Get Profile

GET /api/profiles/:username

Authentication optional, returns a Profile

Follow user

POST /api/profiles/:username/follow

Authentication required, returns a Profile

No additional parameters required

Unfollow user

DELETE /api/profiles/:username/follow

Authentication required, returns a Profile

No additional parameters required

Invoke a password reset

POST /api/users/reset/password

Example request body:

{
  "user":{
    "email": "[email protected]"
  }
}

No authentication required, sends a password reset link to the email

Accepted fields: email

Reset password

PATCH /api/user/reset-password/<token>

Example request body:

{
  "user":{
    "password": "new_password"
  }
}

Authentication required, returns the User

Accepted fields: emailusernamepassword

List Articles

GET /api/articles

Returns most recent articles globally by default, provide tagauthor or favorited query parameter to filter results

Query Parameters:

Filter by tag:

?tag=AngularJS

Filter by author:

?author=jake

Favorited by user:

?favorited=jake

Limit number of articles (default is 20):

?limit=20

Offset/skip number of articles (default is 0):

?offset=0

Authentication optional, will return multiple articles, ordered by most recent first

Feed Articles

GET /api/articles/feed

Can also take limit and offset query parameters like List Articles

Authentication required, will return multiple articles created by followed users, ordered by most recent first.

Get Article

GET /api/articles/:slug

No authentication required, will return single article

Create Article

POST /api/articles

Example request body:

{
  "article": {
    "title": "How to train your dragon",
    "description": "Ever wonder how?",
    "body": "You have to believe",
    "tags": ["reactjs", "angularjs", "dragons"]
  }
}

Authentication required, will return an Article

Required fields: titledescriptionbody

Optional fields: tagList as an array of Strings

Update Article

PUT /api/articles/:slug

Example request body:

{
  "article": {
    "title": "Did you train your dragon?"
  }
}

Authentication required, returns the updated Article

Optional fields: titledescriptionbody

The slug also gets updated when the title is changed

Delete Article

DELETE /api/articles/:slug

Authentication required

Add Comments to an Article

POST /api/articles/:slug/comments

Example request body:

{
  "comment": {
    "body": "His name was my name too."
  }
}

Authentication required, returns the created Comment Required field: body

Get Comments from an Article

GET /api/articles/:slug/comments

Authentication optional, returns multiple comments

Delete Comment

DELETE /api/articles/:slug/comments/:id

Authentication required

Favorite Article

POST /api/articles/:slug/favorite

Authentication required, returns the Article No additional parameters required

Unfavorite Article

DELETE /api/articles/:slug/favorite

Authentication required, returns the Article

No additional parameters required

Update a tag(s) on an article

PUT /api/articles/<slug>/

Example request body:

{
  "article": {
    "title": "How to train your dragon",
    "description": "Ever Wonder how?",
    "body": "Keep reading...",
    "tags": ["tag1", "tag2"]
  }
}

Authentication required, will return an Article

Get Tags

GET /api/articles/tags/tag_list/

Authentication required, returns multiple tags.

Get a Tag

GET /api/articles/tags/tag_list/<tag_id>

Authentication and super user required, returns a tag.

Delete a Tag

DELETE /api/articles/tags/tag_list/<tag_id>

Authentication and super user required.

Update a Tag

UPDATE /api/articles/tags/tag_list/<tag_id>

Example request body:

{
  "tag_name": "update_to_me"
}

Authentication and super user required. returns a tag.

Report Article

POST /api/articles/reports/<slug>/

Example request body:

{
  "report_message": "let me report this issue"
}

Required fields: report_message.

Authentication required, returns a report.

Get all Reports of all Articles

GET /api/articles/reports/

Authentication and super user required, returns multiple reports.

Get all Reports on a single Article

GET /api/articles/reports/<slug>/

Authentication and super user required, returns multiple reports.

Steps to install the project locally.
  1. Install PostgresQL on the machine.

  2. Run pip install -r requirements.txt to install all the project requirements.

  3. Set your environment Variables Below :

    • SECRET_KEY
  4. Then RUN your application.

  • To run it on your local machine;

    python3 manage.py runserver

    Deployment

Run pip install -r requirements.txt to install all the project requirements.

Creating your Heroku app

  • Log into your heroku dashboard and create a pipeline

alt txt

  • Connect the pipeline apps to your Github repo

alt txt

  • Create staging and production apps and set the staging app to auto deploy from the develop branch and the production app to auto deploy from master.

alt txt

  • Add a database to the app

alt txt

Read more.... https://devcenter.heroku.com/articles/heroku-postgresql

  • Setup the environment variables in the app settings.

alt txt

Follow this link for more instructions on how to deploy a django application on Heroku.

https://devcenter.heroku.com/articles/django-app-configuration

You may add a review app to your pipeline by enabling Review apps.

More about Review apps, https://devcenter.heroku.com/articles/github-integration-review-apps

After deploying the app, you can select "Open app" from the top right corner of your dashboard. Here you will get access to the link of your deployed app.

Link to our app

https://ah-backend-staging.herokuapp.com/

ah-backend-iroquois's People

Contributors

api-imperfect avatar eltronix avatar estaer avatar huxaiphaer avatar malep2007 avatar reiosantos avatar

Watchers

 avatar  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.