Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmsc388Bwinter2022-student
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrej Rasevic
cmsc388Bwinter2022-student
Commits
07611477
Commit
07611477
authored
3 years ago
by
Andrej Rasevic
Browse files
Options
Downloads
Patches
Plain Diff
adding exercise 4
parent
bd24d400
No related branches found
No related tags found
No related merge requests found
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exercises/exercise4/MyContacts/routes/api/v1/contacts.js
+39
-0
39 additions, 0 deletions
exercises/exercise4/MyContacts/routes/api/v1/contacts.js
with
39 additions
and
0 deletions
exercises/exercise4/MyContacts/routes/api/v1/contacts.js
0 → 100644
+
39
−
0
View file @
07611477
// module that will define all routes associated with contacts
/* In this file you will define all the routes for your api.
You will need to define the following routes:
1) /api/v1/contacts
This route will need to respond to 3 requests:
1) GET: it will respond with the serialized form of all the
contacts in your application and a response code of 200
/api/v1/contacts?firstName=foo&lastName=bar
2) GET: It will return all of the contacts that match the query paramaters
you pass. If none of them match you should respond with an empty array. If more than
one query parameter is passed, the resources that match need to match all of the
conditions, e.g. if you are passing values for both the firstName and lastName then
your matches need to match both query parameters. Note: query params end at the end of the route,
and all come after the ? character and are combined with a &.
3) POST: it will respond to a POST request that will generate a
new instance of a contact and add it to the database.
Your server should respond with a 201 status code and a message saying "successfully added contact".
2) /api/v1/contacts/:id
This route will need to responde to 3 requests:
1) GET: it will respond with the serialized form of the requested
resource and a response code of 200. You will receive the :id from
the req.params.id property. If the resource (contact) is not found in your "database",
then you should respond with a http status code of 404 and a message saying
"the resource was not found" as json.
/api/v1/contacts/:id
3) PUT: it will update the resource with the information attached in
the req.body property.
Your route should respond with a 201 response code along with the updated
resource otherwise 404 with an error message of "unable to update resource".
4) DELETE: it will remove the contact from the collection with the matching id
in the request.params object and respond with a status code of 201 along with
the deleted resource in the response. If the resource is not found the route should
respond with a 404 error and message "resource not found".
Hint: when sending your response you should follow the following examples:
res.status(404).json({error: 'Contact not found'})
res.status(200).json(contacts)
res.status(201).json(data)
*/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment