Functions
The functions live on Handler in src/Presentation/LambdaFunction/LambdaFunction.cs, each marked [LambdaFunction]. Requests are read case-insensitively. Responses use the camelCase property names shown here, and properties with no value are left out.
The image runs GetMovies unless you pass a different handler name. Lambda Annotations generates the class each one names, and src/Presentation/serverless.template lists them all:
Presentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_GetMovies_Generated::GetMoviesPresentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_GetAuthors_Generated::GetAuthorsPresentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_GetReviews_Generated::GetReviewsPresentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_HttpGetMovies_Generated::HttpGetMoviesPresentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_HttpGetAuthors_Generated::HttpGetAuthorsPresentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_HttpGetReviews_Generated::HttpGetReviewsWorksOnMyMachine.Movies stands in for the name you gave your solution.
GetMovies
Section titled “GetMovies”Lists movies ordered by title, one page at a time, optionally only those whose title contains a search term.
Request
Section titled “Request”| Property | Type | Default | Rules |
|---|---|---|---|
query |
string | none | Up to 100 characters. Matches the title, ignoring case |
offset |
integer | 0 |
0 or more |
limit |
integer | 10 |
1 to 50 |
{ "query": "space", "offset": 0, "limit": 2 }Response
Section titled “Response”A page of movies.
| Property | Type | Description |
|---|---|---|
id |
guid | The movie’s id |
title |
string | The movie’s title |
reviewCount |
integer | How many reviews the movie has |
averageStars |
number | The average rating to one decimal place. Left out when there are no reviews |
{ "items": [ { "id": "cb188ef6-14e7-f85f-2f78-924c2ab26b28", "title": "Deep Space Gardeners", "reviewCount": 5, "averageStars": 3.4 }, { "id": "dfefa450-5454-6a4d-a4aa-95a9b047c17b", "title": "Postcards from Outer Space", "reviewCount": 1, "averageStars": 3 } ], "totalCount": 4, "nextOffset": 2}GetAuthors
Section titled “GetAuthors”Lists authors ordered by last name then first name, one page at a time, optionally only those whose name contains a search term.
Request
Section titled “Request”The same as GetMovies. query matches anywhere in the full name, written first name then last name.
Response
Section titled “Response”A page of authors.
| Property | Type | Description |
|---|---|---|
id |
guid | The author’s id |
firstName |
string | The author’s first name |
lastName |
string | The author’s last name |
reviewCount |
integer | How many reviews the author has written |
averageStars |
number | The average rating they give. Left out when there are no reviews |
{ "items": [ { "id": "01fa8b58-05d2-abd4-e55c-2633222dd0a5", "firstName": "Jana", "lastName": "Auer", "reviewCount": 9, "averageStars": 3.3 }, { "id": "1cc2ad51-61c5-63ee-dd6e-15308cfe6e51", "firstName": "Caroline", "lastName": "Bins", "reviewCount": 10, "averageStars": 3.2 } ], "totalCount": 15, "nextOffset": 2}GetReviews
Section titled “GetReviews”Lists reviews ordered by movie then author, one page at a time. Filter by movie, by author, by words in the review text and by a minimum star rating, in any combination.
Request
Section titled “Request”| Property | Type | Default | Rules |
|---|---|---|---|
movieId |
guid | none | Only reviews of this movie |
authorId |
guid | none | Only reviews by this author |
query |
string | none | Up to 100 characters. Matches the review text, ignoring case |
minStars |
integer | none | 1 to 5. Only reviews with at least this many stars |
offset |
integer | 0 |
0 or more |
limit |
integer | 10 |
1 to 50 |
{ "movieId": "cb188ef6-14e7-f85f-2f78-924c2ab26b28", "limit": 2 }Response
Section titled “Response”A page of reviews.
| Property | Type | Description |
|---|---|---|
id |
guid | The review’s id |
stars |
integer | The rating, from 1 to 5 |
reviewedMovie |
object | The reviewed movie’s id and title. Its reviewCount is always 0 here, so use GetMovies for the real numbers |
reviewAuthor |
object | The author’s id, firstName and lastName. Its reviewCount is always 0 here, so use GetAuthors for the real numbers |
text |
string | What the author said about the movie. Left out when there’s no text |
{ "items": [ { "id": "45911e6f-a366-417b-1453-f34097338ee2", "stars": 5, "reviewedMovie": { "id": "cb188ef6-14e7-f85f-2f78-924c2ab26b28", "title": "Deep Space Gardeners", "reviewCount": 0 }, "reviewAuthor": { "id": "1cc2ad51-61c5-63ee-dd6e-15308cfe6e51", "firstName": "Caroline", "lastName": "Bins", "reviewCount": 0 }, "text": "Everyone involved should be very proud." }, { "id": "8832846c-4100-e92a-0b66-e59dcfde2acc", "stars": 3, "reviewedMovie": { "id": "cb188ef6-14e7-f85f-2f78-924c2ab26b28", "title": "Deep Space Gardeners", "reviewCount": 0 }, "reviewAuthor": { "id": "1cc2ad51-61c5-63ee-dd6e-15308cfe6e51", "firstName": "Caroline", "lastName": "Bins", "reviewCount": 0 }, "text": "I laughed twice and looked at my phone once." } ], "totalCount": 5, "nextOffset": 2}Every function returns one page of results.
| Property | Type | Description |
|---|---|---|
items |
array | The results on this page |
totalCount |
integer | The number of results across every page |
nextOffset |
integer | The offset that fetches the next page. Left out on the last page |
To read everything, start at offset 0 and keep sending the nextOffset back until it’s missing.
Errors
Section titled “Errors”Errors come back in Lambda’s standard error format, with the exception type in errorType.
errorType |
When |
|---|---|
ValidationException |
A request breaks one of the rules above. errorMessage lists every rule it broke |
NotFoundException |
A function that gets one thing by id, like the one in Add a function, can’t find it |
TaskCanceledException or OperationCanceledException |
The invocation ran out of time and the handler stopped the work |
Validation failed: -- Limit: A limit must be between 1 and 50. Severity: ErrorOver HTTP
Section titled “Over HTTP”The three lists are also on an API Gateway HTTP API, each as its own function with an Http prefix. They take the same inputs from the query string and return the same page as the body. The stack’s ApiUrl output is the address.
| Route | Function | Query string |
|---|---|---|
GET /movies |
HttpGetMovies |
query, offset, limit |
GET /authors |
HttpGetAuthors |
query, offset, limit |
GET /reviews |
HttpGetReviews |
movieId, authorId, query, minStars, offset, limit |
curl "${API_URL}movies?query=space&limit=2"| Status | When |
|---|---|
200 |
It worked. The body is the page |
400 |
The query string breaks a rule above, or an id isn’t a GUID. The body is application/problem+json |
500 |
Anything else, such as running out of time. Lambda logs the error |
{ "title": "One or more validation errors occurred.", "status": 400, "errors": { "Limit": ["A limit must be between 1 and 50."] }}