Skip to content

TheSinding/randomly-nice-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alt tag

An API that say's randomly nice things to you!

The world of the internet, can sometimes be a grim place, and very negative.

This project aims to combat that "trend".

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them

npm
node

Installing

It's easy to install!

Clone the repo

git clone https://github.com/TheSinding/Randomly-nice 
cd randomly-nice

Run npm install / yarn install

npm install

Start the server

# Start development live-reload server
npm run dev

# Start production server:
npm start

Methods Quick

URIs relative to http://localhost:9000/api (Or where ever yours is), unless otherwise noted.

Method Description Arguments
GET Requests
GET /sentences Returns all sentences in database as json
GET /sentences/:amount Returns (amount) of random sentences as json amount
GET /sentences/random Returns a random sentence as json
POST Request
POST /sentences Adds a new sentence if it's approved JSON obj with array

Sentences

GET /sentences           # Returns all sentences in database as json

example response

 [
  {
    "_id": "58f22a8de62e1349dbc7b00b",
    "sentence": "You have kind eyes",
    "__v": 0,
    "topic": [
      null
    ]
  },
  { 
   ...
  }
]
GET /sentences/:amount  # Returns (amount) of random sentences as json

example response

[
  "You're more fun than bubble wrap.",
  "I appreciate all of your opinions."
]
GET /sentences/random  # Returns a random sentence as json

example response

[
  {
    "_id": "58f22b6a1e348d4a74ae30bc",
    "sentence": "You're spontaneous, and I love it!",
    "__v": 0,
    "topic": [
      null
    ]
  }
]

POST

The POST request, is checked against the AFINN 165 list. If it's approved it adds its to the database.

GET /sentences  # Adds a new sentence if it's approved

example request

{
  "sentences": [
    "You eyes are as beautiful as the sea itself",
    "You are an idiot"
    ]
}

example response

{
  "1": {
    "Sentence": "You eyes are as beautiful as the sea itself",
    "Score": {
      "score": 3,
      "comparative": 0.3333333333333333,
      "tokens": [
        "you",
        "eyes",
        "are",
        "as",
        "beautiful",
        "as",
        "the",
        "sea",
        "itself"
      ],
      "words": [
        "beautiful"
      ],
      "positive": [
        "beautiful"
      ],
      "negative": []
    },
    "accepted": true
  },
  "2": {
    "Sentence": "You are an idiot",
    "Score": {
      "score": -3,
      "comparative": -0.75,
      "tokens": [
        "you",
        "are",
        "an",
        "idiot"
      ],
      "words": [
        "idiot"
      ],
      "positive": [],
      "negative": [
        "idiot"
      ]
    },
    "accepted": false
  }
}

Built With

Authors

  • Simon Sinding - Initial work
  • Peter Brink - Cosmetic work on the sample page

License

This project is licensed under the MIT License - see the LICENSE.md file for details