Giter Club home page Giter Club logo

twit-api's Introduction

TWIT-API

Background

An API/service that is built with Java to mimic the behavior of Twitter. This API is built ontop of Spring framework and utilises MongoDB Atlas as a cloud database provider.

Spring Frameworks

  • Spring Web
  • Spring Security
  • Spring Data MongoDB
  • Lombok

Special Considerations

  • Users in the database should be unique
  • User's follower and following lists should be filled with unique users
  • User A should not be allowed to unfollow user B if user A is not in user B's list of followers
  • User A should not be allowed to reply to user B's tweets if user A is not in user B's list of followers
  • User should not be allowed to pin more than one tweet

Hosting/Deployment

The following domains are hosted on Railway.app

To Get Started (two methods)

Authorization Feature in Postman Client

inside postman client under authoriszation tab, fill in the following:

  • Type: Basic Auth
  • Username: admin or user
  • Password: password

OR add the following as a header

  • header key: Authorization
  • header value for ADMIN role: Basic YWRtaW46cGFzc3dvcmQ=
  • header value for USER role: Basic dXNlciBwYXNzd29yZA==

important note:

  • ADMIN Role is able to communicate with all API methods
  • USER Role is able to communicate with all API methods except for:
    • Get all users GET
    • Get all tweets GET
    • Create new user POST
    • Delete user DELETE

Method 1: use the Host Domains provided and API Guides to test the API using a tool like Postman

For example, to get a list of users:

Method 2: clone and run service locally

  • clone this git repository into your local folder
git clone 
  • go into the folder and open with your favorite IDE (intelliJ)
cd <folder> && idea pom.xml
  • inside main/resources & test/resources folders, create a file called env.properties and then update the MongoDB Atlas connection string
DB_USER=<mongoDB_user>
DB_PWD=<mongoDB_password>
DB_ENDPOINT=<mongoDB_endpoint>
DB_NAME=<mongoDB_name>

Users API Guide

create a new user POST

http://localhost:8080/api/users
  • JSON body
{
    "userName": "jack",
    "userEmail": "[email protected]"
}
  • sample output
{
    "userId": "641c599463a2a40208bb376d",
    "userName": "jack",
    "userEmail": "[email protected]",
    "userFollowing": [],
    "userFollower": []
}

follow a user POST

http://localhost:8080/api/users/<userName>/follow-user?username=<userNameToFollow>
  • sample URI
http://localhost:8080/api/users/jack/follow-user?username=cindy
  • sample output
{
    "userId": "641c599463a2a40208bb376d",
    "userName": "jack",
    "userEmail": "[email protected]",
    "userFollowing": [
        "cindy"
    ],
    "userFollower": []
}

unfollow a user POST

http://localhost:8080/api/users/<userName>/unfollow-user?username=<userNameToUnfollow>
  • sample URI
http://localhost:8080/api/users/jack/unfollow-user?username=cindy
  • sample output
{
    "userId": "641c599463a2a40208bb376d",
    "userName": "jack",
    "userEmail": "[email protected]",
    "userFollowing": [],
    "userFollower": []
}

delete a user DELETE

http://localhost:8080/api/users/<userName>

retrieve all users GET

http://localhost:8080/api/users

retrieve a user GET

http://localhost:8080/api/users/<userName>

retrieve a list of user's following GET

http://localhost:8080/api/users/<userName>/following

retrieve a list of user's followers GET

http://localhost:8080/api/users/<userName>/followers

Tweets API Guide

compose a tweet POST

http://localhost:8080/api/tweets/compose?username=<userName>
  • JSON body
{
    "tweetContent" : "I'm Cindy. This is my 1st tweet!"
}
  • sample output
{
    "tweetId": "642048e6e18dd46795019f7e",
    "tweetContent": "I'm Cindy. This is my 1st tweet!",
    "pinned": false,
    "tweetReplies": [],
    "user": {
        "userId": "642048a8e18dd46795019f7d",
        "userName": "cindy",
        "userEmail": "[email protected]",
        "userFollowing": [],
        "userFollower": []
    }
}

delete a tweet DELETE

http://localhost:8080/api/tweets/<tweetId>

pin a single tweet PUT

http://localhost:8080/api/tweets/<userName>/status/<tweetId>?pinned=<true or false>

retrieve all tweets GET

http://localhost:8080/api/tweets

retrieve a list of user's tweets GET

http://localhost:8080/api/tweets/<userName>

retrieve a user's specific tweet GET

http://localhost:8080/api/tweets/<userName>/status/<tweetId>

Replies API Guide

reply to a tweet POST

http://localhost:8080/api/replies/tweet?username=<userName>&to=<userNameToReply>&tweetId=<tweetId>
  • JSON body
{
    "replyContent" : "I'm Jack. I am replying to Cindy's 1st tweet!"
}
  • sample output
{
    "tweetId": "642048e6e18dd46795019f7e",
    "tweetContent": "I'm Cindy. This is my 1st tweet!",
    "pinned": false,
    "tweetReplies": [
        {
            "replyId": "642049e5e18dd46795019f7f",
            "replyContent": "I'm Jack. I am replying to Cindy's 1st tweet!",
            "user": {
                "userId": "642048a0e18dd46795019f7c",
                "userName": "jack",
                "userEmail": "[email protected]"
            },
            "userReplyTo": {
                "userId": "642048a8e18dd46795019f7d",
                "userName": "cindy",
                "userEmail": "[email protected]"
            }
        }
    ],
    "user": {
        "userId": "642048a8e18dd46795019f7d",
        "userName": "cindy",
        "userEmail": "[email protected]",
        "userFollowing": [],
        "userFollower": [
            "jack"
        ]
    }
}

delete a reply DELETE

http://localhost:8080/api/replies/delete?tweetId=<tweetId>&replyId=<replyId>

retrieve a list of user's replies GET

http://localhost:8080/api/replies/<userName>

twit-api's People

Contributors

omgshalihin avatar

Stargazers

 avatar

Watchers

Kostas Georgiou 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.