Skip to content

Morning Standup: For student review tomorrow, it would be great if we could demo refactoring the app we made last week to use a REST API. But we don't have a server for it. Me: I'll do it!

License

Notifications You must be signed in to change notification settings

jasonflorentino/plant-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

  • Gets an array of all plants.

/plants/:id

  • Gets a single plant by its id.
  • Example response:
{
  "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

  • Adds a new plant record.
  • Requires a body:
{
  "name": "Name",
  "type": "Type",
  "water_frequency": 5, // Number of days
  "image_url": "Url",
  "last_watered": "YYYY-MM-DD" // Optional
}
  • Response: The newly created plant object

πŸ₯€ DELETE

/plants/:id

  • Deletes a single plant by its id.
  • Response: # of plant records

πŸ€ PUT

/plants/edit/:id

  • Edits a plant by its id.
  • Requires a body with the properties to be updated. Example:
{
  "name": "Michael",
  "water_frequency": 5
}
  • Response: The updated plant object

/plants/water/:id

  • Updates the last_watered date to the current time.
  • Response: The updated plant object

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 ---

About

Morning Standup: For student review tomorrow, it would be great if we could demo refactoring the app we made last week to use a REST API. But we don't have a server for it. Me: I'll do it!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published