Giter Club home page Giter Club logo

guild_messenger's Introduction

Guild Messenger API

Overview

As requested, this is a very simple Messenger API. With two available endpoints, this API can create new text-based messages between two users, and return messages for a given recipient.

You may review the feature work for these endpoints in this pull request.

Timeframe:

  • ~3 hours coding
  • ~1 hour planning + documentation

Assumptions

  • Users (senders and recipients) have unique integer IDs that will be passed to the API endpoints as parameters
  • Anonymous messages are not allowed (there must be a sender_id given)
  • Empty messages are not allowed (there must be content given)
  • Authorization, Authentication and Registration can be ignored (this is a global API that can be leveraged by anyone, security is not a concern)

Endpoints

Endpoint Parameters Returns
GET /api/v1/messages sender_id (integer, optional field - returns messages from all senders if field is not specified),
recipient_id (integer, required),
limit ("100" or "30d", required)
If Successful: 200 response and a list of all messages meeting the specified parameters, returned in the format outlined by JSON:API,
If Unsuccessful: 400 Bad Request (missing parameters)
POST /api/v1/messages sender_id (integer, required),
recipient_id (integer, required),
content (string, required)
If Successful: 201 Created,
If Unsuccessful: 400 Bad Request (missing parameters)

Sample API Call - Create Message

Request
Verb + Path: POST http://localhost:3000/api/v1/messages
Body:

{
"sender_id": 1234, 
"recipient_id": 5678, 
"content": "Don't worry, about a thing"
}

Response
Status: 201 Created
Body:

{
    "response": "Created"
}

Sample API Call - Get Messages

Request
Verb + Path: GET http://localhost:3000/api/v1/messages
Body:

{
"sender_id": 1234, 
"recipient_id": 5678, 
"limit": "100"
}

Response
Status: 200 OK
Body:

{
    "data": [
        {
            "id": "5",
            "type": "message",
            "attributes": {
                "sender_id": 1234,
                "recipient_id": 5678,
                "content": "Don't worry, about a thing",
                "created_at": "2021-08-27T13:55:26.670Z"
            }
        },
        {
            "id": "4",
            "type": "message",
            "attributes": {
                "sender_id": 1234,
                "recipient_id": 5678,
                "content": "Don't worry, about a thing",
                "created_at": "2021-08-27T00:17:17.236Z"
            }
        },
        {
            "id": "1",
            "type": "message",
            "attributes": {
                "sender_id": 1234,
                "recipient_id": 5678,
                "content": "This is a message for you-ooh-ooh",
                "created_at": "2021-08-26T22:16:28.820Z"
            }
        }
    ]
}

Schema

Screen Shot 2021-08-26 at 6 46 57 PM

Technologies

Local Setup

To setup these endpoints locally:

  1. clone this repo to your local machine
  2. run bundle install
  3. run rails db:{create,migrate} to setup the database
  4. run rails s and navigate to http://localhost:3000 with the desired endpoint for get requests, and/or use a tool like Postman for post requests.

Next Steps

Given additional time, here's what I'd like to work on:

  • Refactor! Cleanup methods for increased readability, DRY-ness and SRP
  • Add an ErrorSerializer to return 400 responses in the JSON:API convention
  • Refactor to provide more detailed error responses (which field is mising, e.g.)
  • Include additional edge case handling:
    • Set a character limit on message content to ensure it fits within the database
  • Leverage a gem like FactoryBot to cleanup test setup

guild_messenger's People

Contributors

aliyamerali avatar

Watchers

James Cloos 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.