Try   HackMD

Simple Twitter API - README

A RESTful API server for Simple Twitter project built with Node.js, Express framework, and MySQL.

This is a collaborate project to make a simple Twitter web app. And the server-side API majors in authentication and data CRUD features.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Simple Twitter API is hosted on Heroku now. You can give it a try by using following base URL.

https://twitter-api-2022.herokuapp.com

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Simple Twitter Demo is hosted here. You can use the following accounts to login and try all the features:

Admin
account: root
password: 12345678

Users(provide 11 seed users)
account: user1 (~user11)
password: 12345678

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Simple Twitter Frontend is developed by Vue.js (repo link).

API Features

Authentication

Check if the user is authenticated and authorized. Some routes are available to use after login, some are admin/user role only. Please refer to the API documents.

Admin

  • Signin background(後台)
  • Get the list of all users
  • Get the list of all tweets
  • Delete tweet

Users

  • Signin foreground(前台)
  • Signup an new account
  • Post, like, reply or read a tweet
  • Follow, unfollow other users
  • Edit own profile(include upload image)
  • Get data of a certain user(personal info, tweets, likes, followings, followers, replies)

API Documents

Build a local API server

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Node.js, Express and MySQL are installed.

Installing

Clone the repo

git clone https://github.com/ritachien/twitter-api-2022.git

Install dependencies

npm install

Create file and folder in root

  • Create a .env file and set variables(see .env.example). Notice that JWT_SECRET is required and IMGUR_CLIENT_ID is optional.
  • Make a temp folder for image upload feature.

Setting for database

  • Modify /config/config.json
"username": <your mysql username>,
"password": <your mysql password>,
  • Create database to your MySQL
CREATE DATABASE ac_twitter_workspace;
CREATE DATABASE ac_twitter_workspace_test;
  • Migrations and seeds(run in terminal)
npx sequelize db:migrate
npx sequelize db:seed:all

Start the server

npm start

Auto-testing

There are auto-test files for models and requests in this repo. Look for more details in /test folder.

Set NODE_ENV before test

export NODE_ENV=test  // macOS
set NODE_ENV=test  // windowsOS

Run the tests

npm run test

Set NODE_ENV after test

export NODE_ENV=developemnt  // macOS
set NODE_ENV=development  // windowsOS

Check current enviornmment

echo $NODE_ENV  // macOS
echo %NODE_ENV%  // windowsOS

Built With

Authors

List of contributors who participated in this project.

tags: API-doc