Code Monkey home page Code Monkey logo

postchat-api's Introduction

Postchat API

API-driven chat for an API-driven world.

You won't find any message input boxes here... make a POST request to send a message!

Messages can be viewd in real time from https://postchat.netlify.app/rooms/:roomId when using prod configuration.

Built with Node/Express/Typescript/MongoDB

Docs

Base url: https://postchat-api.herokuapp.com/api/v1

Create a room

POST /rooms

Create a new room with a given title

Example request body

{
  "title": "Fauxtech Institute"
}

Example response

{
  "_id": "608f50f1a100f1eea3e01b01",
  "title": "Fauxtech Institute",
  "messages": []
}

Get a room

GET /rooms/:roomId

Returns messages and info for room with given id

Example response

{
  "_id": "608f50f1a100f1eea3e01b01",
  "title": "Fauxtech Institute",
  "messages": [
    {
      "_id": "608f50f1a100f1eea3e01b01",
      "text": "laboris esse nulla cillum",
      "username": "fugiat"
    },
    {
      "_id": "608f5a7b39abc8f2152d67a6",
      "text": "aliqua incididunt culpa Excepteur Duis",
      "username": "dolore"
    }
  ]
}

Send a message to a room

POST /rooms/:roomId/message

Sends a message to room with given id in path

Example request body

{
  "text": "Look ma', no UI!",
  "username": "postmanaut"
}

Example response

{
  "_id": "208f50f1a100f1eea3e01b01",
  "text": "Look ma', no UI!",
  "username": "postmanaut"
}

Development

Pre-reqs

Use a node version manager such as n to switch node versions to 16.x. For example:

n 16.0.0

Install

yarn install

Copy env vars

Copy the env defaults

cp .env.default .env

Then fill in the MONGO_URI value with a valid URI. (see Data)

Start dev server

yarn dev

The dev server serves typescript files directly via ts-node, and automatically reloads when any file changes are made in src.

Data

This API uses a free MongoDB cluster via MongoDB Atlas to persist data.

Use exisiting dev db

If you would like to use the existing production database, contact @clairefro for the credentials.

Create your own cluster

If you would like to create your own database for local testing or a fork of this API, create an account and create a new cluster using the defaults.

Once your cluster is created, click the CONNECT button and follow the instructions for connecting a db instance to an application. Be sure to whitelist your IP address. You will be asked to create a user with a password - jot this down. You will need to supply these credentials in the url for MONGO_URI variable in this project's .env file.

Deployment

To deploy to Heroku

  1. Request access as a collaborator on the postchat-api github project (contact @clairefro)
  2. Request access as a collaborator on the postchat-api heroku project (contact @clairefro)
  3. Ensure your latest changes are merged into main and you've pulled the latest changes
  4. yarn deploy

This app uses build packs:

  1. heroku/nodejs

postchat-api's People

Contributors

clairefro avatar

Watchers

 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.