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
A simple Express server for week 7 review
- Clone or download this repo.
- Install dependencies:
$ npm install
- Set environment variables: Create
.env
based on.env_sample
and set the port number and API key. - Start the server:
$ node index.js
# Or run with change watcher:
$ npm run dev
You must provide an API key as a query string to every request.
?api_key=<YOUR API KEY>
- Gets an array of all plants.
- 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
}
- 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
- Deletes a single plant by its id.
- Response: # of plant records
- 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
- Updates the last_watered date to the current time.
- Response: The updated plant object
All GraphQL queries should be sent as GET or POST requests to /graphql
Plant {
id ID
name! String
type! String
water_frequency! Int
image_url! String
last_watered! Float
}
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 | --- |
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 | --- |
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 | --- |
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 | --- |
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 | --- |
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 | --- |