Coder Social home page Coder Social logo

chatty's Introduction

(This was a job interview exercise a billion years ago.)

This API will be used to control users exchanging messages between each other.

The command takes two optional arguments:

  • -p Is the the port number. Default is 8000.
  • -m Is the MongoDB URL. Default is whatever's in your secret.txt file on the same folder as the executable.

Here are some things you can do with this app:

  • POST request to [URL]/users containing {"name": "User Name","username": "username"} adds that entry to the database.

Example output:

{
    "id": "5a92fe5a7d9b532f98e8bba1",
    "budget": 10,
    "name": "User Name",
    "username": "username",
    "createdAt": "2018-02-25T18:20:10.805Z",
    "updatedAt": "2018-02-25T18:20:10.805Z"
}
  • GET request to [URL]/users/[User ID] gets a user from the database. For example, after the request above has been processed, a request to [URL]/users/5a92fe5a7d9b532f98e8bba1 would yield the same output.

  • POST request to [URL]/messages containing {"from": "orange","to": "banana","body": "This is a test message."} adds that message to the database.

Example output:

{
    "id": "5a93000c7d9b532f98e8bba2",
    "from": "orange",
    "to": "banana",
    "body": "This is a test message.",
    "sentAt": "2018-02-25T18:27:24.885Z"
}
  • GET request to [URL]/message/[Message ID] gets a message from the database. For example, after the request above has been processed, a request to [URL]/messages/5a93000c7d9b532f98e8bba2 would yield the same output.

  • GET request to [URL]/messages?to=username gets all messages addressed to that username.

Example output:

{
    "messages": [
        {
            "id": "5a8d76807d9b537448d19b30",
            "from": "orange",
            "to": "banana",
            "body": "This is a test message.",
            "sentAt": "2018-02-21T13:39:12.767Z"
        },
        {
            "id": "5a93000c7d9b532f98e8bba2",
            "from": "apple",
            "to": "banana",
            "body": "This is another test message.",
            "sentAt": "2018-02-25T18:27:24.885Z"
        }
    ]
}
  • GET request to [URL]/listusers lists all users. This is not on spec, it's there as a development aid.

Example output:

[
    {
        "id": "5a8d75057d9b53706595116a",
        "budget": 9,
        "name": "Orange",
        "username": "orange",
        "createdAt": "2018-02-21T13:32:53.509Z",
        "updatedAt": "2018-02-21T13:39:13.159Z"
    },
    {
        "id": "5a8d750d7d9b53706595116b",
        "budget": 8,
        "name": "Banana",
        "username": "banana",
        "createdAt": "2018-02-21T13:33:01.239Z",
        "updatedAt": "2018-02-21T13:38:52.757Z"
    }
]
  • GET request to [URL]/listmsg lists all messages. This is not on spec, it's there as a development aid.

Example output:

[
    {
        "id": "5a8d766c7d9b537448d19b2f",
        "from": "banana",
        "to": "orange",
        "body": "Message.",
        "sentAt": "2018-02-21T13:38:52.358Z"
    },
    {
        "id": "5a93000c7d9b532f98e8bba2",
        "from": "orange",
        "to": "banana",
        "body": "This is a test message.",
        "sentAt": "2018-02-25T18:27:24.885Z"
    }
]

chatty's People

Contributors

vkorbes avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

ayo-ajayi

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.