Code Monkey home page Code Monkey logo

flask_rest_api's Introduction

Flask_REST_API for Social Network

Getting Started

Installation:

sudo pip install virtualenv
git clone https://github.com/SkimFelBon/flask_REST_API
cd ./flask_REST_API/
# activate virtualenv
virtualenv env
sudo pip install -r requirements.txt
# pull postgres-image from docker hub: https://hub.docker.com/_/postgres
docker pull postgres
# start docker container
docker run --name my_psql -p 127.0.0.1:3306:3306 -e POSTGRES_PASSWORD=admin -d postgres:latest
# connect to container
docker exec -it my_psql bash

Create database

# connect to postgresql from command line:
psql -U postgres
CREATE DATABASE rest_api;
-- verify that db was created (list all databases with \l command):
\l

from host copy dumpfile to container

docker cp ./dumpfile my_psql:/root/dumpfile
# jump to container and dump data to database:
psql rest_api < dumpfile -U postgres

jump to psql one more time, select db and verify that data exists:

psql -U postgres
-- connect to our database:
\c rest_api
-- verify data:
select * from "user";

also create settings.py

# settings.py
DB_NAME = "rest_api"
USER = "postgres"
PASS = "yourpassword"
SECRET_KEY = 'replace-me'
SQLALCHEMY_DATABASE_URI = f"postgresql://{USER}:{PASS}@localhost/{DB_NAME}?client_encoding=utf8"

start app

flask run

Basic features:

  • POST /api/signup user signup.
  • POST /api/login user login.
  • POST /api/post post creation.
  • PUT /api/like/<int:post_id> post like.
  • PUT /api/unlike/<int:post_id> post unlike.
  • GET /api/analytics/?date_from=2020-02-02&date_to=2020-02-15 analytics about how many likes was made. Analytics aggregated by day
  • GET /api/users/<int:prim_key> search user.
  • user activity an endpoint which will show when user was login last time and when he mades a last request to the service.
  • Implemented token authentication, using JWT

Signup route

http://127.0.0.1:5000/api/signup/
{"first_name":"Edward",
  "last_name":"LaFontainer",
  "password":"12345",
  "email":"[email protected]"}

response:

{
  "message": "Created new User.",
  "user": {
    "email": "[email protected]",
    "first_name": "Edward",
    "id": 4,
    "last_login": null,
    "last_name": "LaFontainer",
    "last_request": null
  }
}

Login route

http://127.0.0.1:5000/api/login/
{"email":"[email protected]","password":"12345"}

response:

{
  "token": "eyJhbG...aHO4-subrC0"
}

Post creation route

http://127.0.0.1:5000/api/post
{"title":"my post", "description":"lorem ipsum dolor sit amet..."}

response:

{
  "message": "Created new post.",
  "post": {
    "author_id": 4,
    "created": "2020-07-19T15:24:49.510789",
    "description": "description",
    "id": 2,
    "title": "title"
  }
}

Like route

http://127.0.0.1:5000/api/like/1

response:

{
  "message": "Liked post"
}

Unlike route

http://127.0.0.1:5000/api/unlike/1

response:

{
  "message": "Unliked post"
}

analytics

http://127.0.0.1:5000/api/analitics/?date_from=2020-07-17&date_to=2020-07-20

response:

{
  "likes_per_day": [
    [
      18.0,
      1
    ],
    [
      19.0,
      2
    ]
  ]
}

search user route

http://127.0.0.1:5000/api/users/1

response:

{
  "user": {
    "email": "[email protected]",
    "first_name": "Amy",
    "id": 1,
    "last_login": "2020-07-19T11:52:23.884529",
    "last_name": "Meyer",
    "last_request": "2020-07-19T11:52:33.849130"
  }
}

flask_rest_api's People

Contributors

skimfelbon avatar

Watchers

 avatar  avatar

flask_rest_api's Issues

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.