-
Notifications
You must be signed in to change notification settings - Fork 0
Adding Other Endpoints
xtreme-steve-elliott edited this page Nov 14, 2017
·
2 revisions
Previous: Introducing an In-Memory Database
In this section, we'll be building out three more endpoints, GetAsync(long id)
, PostAsync(Note note)
and DeleteAsync(long id)
.
- In
NotesController
, theGetAsync(long id)
method should be annotated with[Route("{id}", Name = "GetNoteById")]
. TheName
attribute will be used to reference the endpoint in thePostAsync
endpoint.
- For the success case in
PostAsync
ofNotesController
, return aCreatedAtRouteResult
using:This makes reference to theCreatedAtRoute("GetNoteById", new { id = processedNote.Id }, processedNote)
GetAsync(long id)
endpoint that we annotated earlier, and passes the arguments required via an anonymous dictionary, as well as theNote
itself for the body of the response. - The response from
PostAsync(Note note)
has aRouteValues
member that contains all the values from the anonymous dictionary passed toCreatedAtRoute
. - Remember to annotate your method parameter on
PostAsync(Note note)
with[FromBody]
. - When the
PostAsync(Note note)
endpoint andAddNoteAsync
methods have been added and tested, they can be used in repository tests to replace calls to_context.Notes.Add(note)
withawait _repository.AddNoteAsync(note)
.
Git Tag: adding-other-endpoints
Up Next: Adding Integration Tests