-
That then takes us into our show method, which is meant for showing an individual difficulty. And that's gonna come through as the ID parameter
-
on our route. So just like all of the others, we want to grab our organization from the HTTP context. We don't have a specific get the difficulty action, but this is going to be just simple enough,
-
just like our index method was. So we can just grab it directly off of our organization, reach for the related difficulties, query off of there. And then we just want to add in a where statement
-
where the ID matches the params.id passed in. The params ID is going to be the difficulty ID added as a route parameter on the URL.
-
And then we can call first or fail, meaning that it will either find the first result and return that back, or it will fail out with a 404 error. And if you were curious,
-
we are returning back a promise here of difficulty, but AdonisJS will automatically handle that promise for us awaiting it. And if the promise ends up throwing an exception because it cannot find the record,
-
it will handle that appropriately as well. So we're still a-okay to just directly return back the response that we want here. So we'll give that a save, and we go ahead and jump back in the hopscotch.
-
Let's create a new difficulties request. We'll call this get difficulty, give that a save, switch this back over to a get request.
-
And now rather than doing just slash difficulties, which would return all of our difficulties, we want to specify a specific ID. So 10 is the last result that we created
-
within our store difficulties method. So we'll reach for 10 as the ID there. We no longer need a body for this request. So we should be able to go ahead and just set that back to none.
-
And our headers should be automatically set from our API collection, including our accept and authorization token. Okay, cool. If we go ahead and send this out,
-
we see that we get back our response with an ID of 10 right there, exactly as expected. If we switch this to an ID that does not exist,
-
so maybe 100, for example, send that off. We get back a JSON response of the exception that was captured, which is a 404 as its status code
-
and a message and name of row not found. Perfect.