Field | Type | Description |
---|---|---|
id | int | Primary key |
name | varchar(255) | Company name |
website | varchar(255) | Company website |
Field | Type | Description |
---|---|---|
id | int | Primary key |
company_id | int | Foreign key to company.id |
name | varchar(255) | Product name |
price | int | Product price |
Method | Endpoint | Description |
---|---|---|
GET | /companies | Get all companies |
GET | /companies/:id | Get company by id |
POST | /companies | Create company |
PUT | /companies/:id | Update company |
DELETE | /companies/:id | Delete company |
Method | Endpoint | Description |
---|---|---|
GET | /companies/:company_id/products | Get all products by company id |
GET | /companies/:company_id/products/:id | Get product by id |
POST | /companies/:company_id/products | Create product |
PUT | /companies/:company_id/products/:id | Update product |
DELETE | /companies/:company_id/products/:id | Delete product |
Request
curl -X GET http://localhost:3000/companies
Response
[
{
"id": 1,
"name": "Apple",
"website": "https://www.apple.com"
},
{
"id": 2,
"name": "Google",
"website": "https://www.google.com"
}
]
Request
curl -X GET http://localhost:3000/companies/1
Response
{
"id": 1,
"name": "Apple",
"website": "https://www.apple.com"
}
Request
curl -X POST -H "Content-Type: application/json" -d '{"name":"Microsoft","website":"https://www.microsoft.com"}' http://localhost:3000/companies
Response
{
"id": 3,
"name": "Microsoft",
"website": "https://www.microsoft.com"
}
Request
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Microsoft","website":"https://www.microsoft.com"}' http://localhost:3000/companies/3
Response
{
"id": 3,
"name": "Microsoft",
"website": "https://www.microsoft.com"
}
Request
curl -X DELETE http://localhost:3000/companies/3
Response
{
"id": 3,
"name": "Microsoft",
"website": "https://www.microsoft.com"
}
Request
curl -X GET http://localhost:3000/companies/1/products
Response
[
{
"id": 1,
"company_id": 1,
"name": "iPhone",
"price": 1000
},
{
"id": 2,
"company_id": 1,
"name": "iPad",
"price": 500
}
]
Request
curl -X GET http://localhost:3000/companies/1/products/1
Response
{
"id": 1,
"company_id": 1,
"name": "iPhone",
"price": 1000
}
Request
curl -X POST -H "Content-Type: application/json" -d '{"name":"MacBook","price":2000}' http://localhost:3000/companies/1/products
Response
{
"id": 3,
"company_id": 1,
"name": "MacBook",
"price": 2000
}
Request
curl -X PUT -H "Content-Type: application/json" -d '{"name":"MacBook","price":2000}' http://localhost:3000/companies/1/products/3
Response
{
"id": 3,
"company_id": 1,
"name": "MacBook",
"price": 2000
}
Request
curl -X DELETE http://localhost:3000/companies/1/products/3
Response
{
"id": 3,
"company_id": 1,
"name": "MacBook",
"price": 2000
}