Deprecation Notice

Hi all, I'm sorry to say but starting October 7, 2024 the plant server will no longer be available at plantserver.fun. Going to let the domain expire since I think this server's time has come I don't want to keep paying for the domain. Sorry for any inconvenience! You're welcome to take this and spin it up yourself if you'd like!

Love,

β€”Jason, Sept 2024


πŸͺ΄ Plant Tracker Server

A simple Express server for week 7 review

Installation

  1. Clone or download this repo.
  2. Install dependencies:
$ npm install
  1. Set environment variables: Create .env based on .env_sample and set the port number and API key.
  2. Start the server:
$ node index.js

# Or run with change watcher:
$ npm run dev

Authentication

You must provide an API key as a query string to every request.

?api_key=<YOUR API KEY>

REST API

πŸ’ GET

/plants

/plants/:id

{
  "id": 1,
  "name": "Pam",
  "type": "Big Green One",
  "water_frequency": 7,
  "image_url": "https://images.pexels.com/photos/3644742/pexels-photo-3644742.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940",
  "last_watered": 1620925225646
}

🌱 POST

/plants

{
  "name": "Name",
  "type": "Type",
  "water_frequency": 5, // Number of days
  "image_url": "Url",
  "last_watered": "YYYY-MM-DD" // Optional
}

πŸ₯€ DELETE

/plants/:id

πŸ€ PUT

/plants/edit/:id

{
  "name": "Michael",
  "water_frequency": 5
}

/plants/water/:id

GraphQL API

🌿 Endpoints

All GraphQL queries should be sent as GET or POST requests to /graphql

🌡 Objects

Plant

Plant {
  id ID
  name! String
  type! String
  water_frequency! Int
  image_url! String
  last_watered! Float
}

πŸ’ Queries

plant

Returns one plant by ID.

Name Type Description Required?
Arguments id ID The ID of the plant to get βœ…
Possible Returns plant.* Plant Any requested field from the Plant object ---

plants

Returns a list of plants

Name Type Description Required?
Arguments none --- --- ---
Possible Returns --- Plant[] A list of Plant objects and any of their requested fields ---

🌱 Mutations

addPlant

Creates a new plant

Name Type Description Required?
Arguments name String The name of the new plant βœ…
type String The type of the new plant βœ…
water_frequency Int Number of days after which the plant should be watered βœ…
image_url String The URL for the image of the plant βœ…
last_watered String When the plant was last watered in "YYYY-MM-DD" format ❌
Possible Returns plant.* Plant Any requested field from the newly created Plant object ---

editPlant

Edits a plant given its ID.

Name Type Description Required?
Arguments id ID The ID of the plant to edit βœ…
name String The new name for the plan ❌
type String The new type for the plant ❌
water_frequency Int Number of days after which the plant should be watered ❌
image_url String The new URL for the plant's image ❌
last_watered String When the plant was last watered in "YYYY-MM-DD" format ❌
Possible Returns plant.* Plant Any fields from the updated Plant object ---

deletePlant

Deletes a plant given its ID.

Name Type Description Required?
Arguments id ID The ID of the plant to delete βœ…
Possible Returns plant.id ID The ID of the deleted plant ---

waterPlant

Waters a plant given its ID.

Name Type Description Required?
Arguments id ID The ID of the plant to water βœ…
Possible Returns plant.* Plant Any requested field from the updated Plant object ---