Code Monkey home page Code Monkey logo

chirpr_api's Introduction

chirpr_api

A Twitter esque social media with search Bookmark functionality

Table of Contents

Intoduction

Getting Started

Development Setup

API Walkthrough

Docker

Testing

Live

Introduction

Twitter is a popular micro blogging social media where users can share tweets on their timeline, and also save particulat tweets theyre interested in a bookmarks section. but twitter requires users to keep scrolling in their bookmark sections whenever they're in need of a particular bookmarked tweet. Enter chirpr, chirpr aims to solve this UX problem by introducing searchable boomarks in every user's bookmark section, just by typing particular words in the search bar, bookmarked tweets are filtered by the typed keywords.

Entity Relationship Diagram

My Image

Overview

Getting Started

Installing Dependencies

Python 3.7

Follow instructions to install the latest version of python for your platform in the python docs

Virtual Environment

We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organized. Instructions for setting up a virtual environment for your platform can be found in the python docs

PIP Dependencies

Once you have your virtual environment setup and running, install dependencies by navigating to the /chirpr_api directory and running:

bash

pip install -r requirements.txt
Key Dependencies
  • Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

  • SQLAlchemy and Flask-SQLAlchemy are libraries to handle the lightweight sqlite database.

Development Setup

Download the project starter code locally

git clone https://github.com/jefedcreator/chirpr_api.git
cd chirpr_api/

These are the files relevant for this project:

.

├── models.py
├── settings
    ├── settings.py
├── .venv
├── .env
├── README.md
├── test.py
├── app.py
├── Procfile
├── runtime.txt
├── requirements.txt
├── wsgi.py
├── Dockerfile
├── .gitignore

To comtribute to the upstream repository path from your local repository, use the commands below:

git remote add upstream https://github.com/jefedcreator/chirpr_api.git
git remote -v 
git checkout -b <branch name>

Once you have finished editing your code, you can push the local repository to the Github repository using the following commands.

git add . --all   
git commit -m "your comment"
git push -u origin <branch name>

Initialize and activate a virtualenv using:

python -m virtualenv env
source env/bin/activate

Note - In Windows, the env does not have a bin directory. Therefore, you'd use the analogous command shown below:

source env/Scripts/activate

Install the dependencies:

pip install -r requirements.txt

Run the development server:

export FLASK_APP=myapp
export FLASK_ENV=development # enables debug mode
flask run

To run the server, execute:

flask run --reload

The --reload flag will detect file changes and restart the server automatically.

alternatively, run

python wsgi.py

Verify on the Browser

Navigate to project homepage http://127.0.0.1:5000/ or http://localhost:5000

API Walkthrough

GET '/api/users'

  • Fetches a dictionary of all users in which the keys are the user ids and the value is the corresponding dictionary of the user details
  • Request Arguments: None
  • Returns: An object with a two key,success, that contains a value of True if successful and users, that contains an object of user_obj key: value pairs.
{
  "success" : "True",
  "users": "user_obj"
}

POST '/api/users/create'

Sends a post request in order to create a new user dictionary with user details Request Body:

{
    "id": "user id",
    "name": "user name",
    "url": "user url",
    "tweets": "[]",
}

Returns: An object with a two key,success, that contains a value of True if successful and users, that contains an object of user_obj key: value pairs.

{
    
    "success" : "True",
    "users": "user_obj"
}

POST '/api/login'

Sends a post request in order to login an existing user, receives a json request with user details Request Body:

{
    "id": "user id",
    "name": "user name",
}

Returns: An object with a key,success, that contains a value of True if successful, or False is user does not exist

{
    
    "success" : "True",
}

GET '/api/users/${user_id}'

Fetches entire user details, including tweets for a user specified by their id request argument Request Arguments: id - string Returns: A list of objects with user details for the specified user, and a list of all user tweets

{
    "success": "True",
    "user" : "user_list"
}

GET '/api/tweets'

  • Fetches a dictionary of all tweets in which the keys are the tweet ids and the value is the corresponding dictionary of the tweet details
  • Request Arguments: None
  • Returns: An object with a two key,success, that contains a value of True if successful and tweets, that contains an object of tweets key: value pairs.
{
  "success" : "True",
  "users": "all_tweets"
}

POST '/api/tweets/create'

Sends a post request in order to create a new tweet dictionary with tweet details Request Body:

{
    "id": "tweet id",
    "text": "tweet text",
    "author": "tweet author",
    "timestamp": "123",
    "likes": "[]",
    "replies": "[]",
    "replying_to": ""
}

Returns: An object with a two key,success, that contains a value of True if successful and tweets, that contains an object of all_tweets key: value pairs.

{
    
    "success" : "True",
    "tweets": "all_tweets"
}

GET '/api/tweets/${tweet_id}'

Fetches entire tweet details, including tweets for a user specified by their id request argument Request Arguments: id - string Returns: A list of objects with tweet details for the specified tweet id

{
    "success": "True",
    "user" : "tweet_list"
}

PATCH '/api/tweets/${tweet_id}'

Modifies the likes and replies column specified by the tweet_id. this request checks if a user's likes already exists within the likes array and pops it, else appends to it. this request also checks if a user's replies already exists within the replies array and pops it, else appends to it. this request also checks if a tweet is a reply to another tweet to it, else null.

Request Body:

{
    "likes": "user id",
    "replies": "user replies",
    "replying_to": "tweet id"
}

GET '/api/bookmarks/user_id'

  • Fetches a dictionary of all bookmarks in which the keys are the bookmarks ids and the value is the corresponding dictionary of the bookmark details
  • Request Arguments: None
  • Returns: An object with a two key,success, that contains a value of True if successful and bookmarks, that contains an object of bookmarks key: value pairs.
{
  "success" : "True",
  "tweets": "all_bookmarks"
}

POST '/api/bookmarks/create'

Sends a post request in order to create a new bookmark dictionary with tweet details Request Body:

{
    "id": "bookmark id",
    "text": "bookmark text",
    "author": "bookmark author",
    "timestamp": "123",
    "likes": "[]",
    "replies": "[]",
    "replying_to": ""
}

Returns: An object with a two key,success, that contains a value of True if successful and tweets, that contains an object of all_tweets key: value pairs.

{
    
    "success" : "True",
    "tweets": "all_bookmarks"
}

GET '/api/bookmark/${bookmark_id}'

Fetches entire bookmark details, including bookmarks for a user specified by their id request argument Request Arguments: id - string Returns: A list of objects with tweet details for the specified bookmark id

{
    "success": "True",
    "tweets": "bookmark_list"
}

DELETE '/api/bookmark/${bookmark_id}'

deletes entire bookmark details, including bookmarks for a user specified by their id request argument Request Arguments: id - string Returns: success with value of True

{
    "success": "True"
}

POST '/api/bookmarks/search'

Receives a json request search_term and filters the Bookmark database, and returns a list of Bookmarks containing id and text object that match specified request

{
    "success": "True",
    "bookmarks": "bookmarks"
}

Docker

After cloning, Navigate to the chirpr_api folder

cd chirpr_api

Open the VS code editor to display the file content

code .

Build an image

docker build -t chirprapi .

check list of images

docker image ls

Create and run a container

docker run --name chirprapi -p 80:8080 chirprapi

Access the application

# Mac/Linux users only
curl http://0.0.0.0/
# Windows users using WSL/GitBash
curl http://127.0.0.1:80/

Testing

python test.py

Live server

chirpr

chirpr_api's People

Contributors

jefedcreator avatar

Watchers

 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.