Skip to content

Commit

Permalink
all basic existing solution content
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Mar 17, 2024
1 parent 73824bf commit c1c2ab5
Show file tree
Hide file tree
Showing 38 changed files with 2,609 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ public void setup(final Challengers challengers,
if(contentPath.endsWith(bc)){
bcHeader.append( bc );
}else {
bcHeader.append(String.format(" [%s](%s) > ", bc, bcPath));
// if there is an index file then show the breadcrumb
if(getResourceAsStream(contentFolder + bcPath + ".md")!=null) {
bcHeader.append(String.format(" [%s](%s) > ", bc, bcPath));
}
}
}
bcPath = bcPath + "/";
Expand Down Expand Up @@ -393,12 +396,13 @@ private InputStream getResourceAsStream(String fileName) {

// the stream holding the file content
if (inputStream == null) {
throw new IllegalArgumentException("file not found! " + fileName);
logger.error("content file not found: " + fileName);
return null;
} else {
return inputStream;
}

}

private void pageNotFoundHtmlResponse(Response response, String bodyStringAppend) {
response.status(404);
response.type("text/html");
Expand Down
4 changes: 2 additions & 2 deletions challenger/src/main/resources/content/apichallenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: API Challenges Documentation

# API Challenges

You can find solutions to all of the challenges [here](apichallenges/howto):
You can find solutions to all of the challenges [here](apichallenges/solutions):

- [Solutions for the API Challenges](apichallenges/howto)
- [Solutions for the API Challenges](apichallenges/solutions)

28 changes: 0 additions & 28 deletions challenger/src/main/resources/content/apichallenges/howto.md

This file was deleted.

124 changes: 124 additions & 0 deletions challenger/src/main/resources/content/apichallenges/solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
title: API Challenges Solution Index
---

# API Challenge Solutions

## Getting Started

- [POST /challenger (201)](/apichallenges/solutions/create-session/post-challenger-201)

## First Real Challenge

- [GET /challenges (200)](/apichallenges/solutions/first-challenge/get-challenges-200)

## GET Challenges

- [GET /todos (200)](/apichallenges/solutions/get/get-todos-200)
- [GET /todo (404)](/apichallenges/solutions/get/get-todo-404)
- [GET /todos id (200)](/apichallenges/solutions/get/get-todos-id-200)
- [GET /todos id (404)](/apichallenges/solutions/get/get-todos-id-404)
- [GET /todos ?filter (200)](/apichallenges/solutions/get/get-todos-200-filter)

## HEAD Challenges

- [HEAD /todos id (200)](/apichallenges/solutions/head/head-todos-200)

## Creation Challenges with POST

- [POST /todos id (201)](/apichallenges/solutions/post-create/post-todos-201)
- [POST /todos (400) doneStatus](/apichallenges/solutions/post-create/post-todos-400)
- POST /todos (400) title too long
- POST /todos (400) description too long
- POST /todos (201) max out content
- POST /todos (413) content too long
- POST /todos (400) extra

## Creation Challenges with PUT

- PUT /todos/{id} (400)

## Update Challenges with POST

- [POST /todos id (200)](/apichallenges/solutions/post-update/post-todos-id-200)
- POST /todos/{id} (404)

## Update Challenges with PUT

- PUT /todos/{id} full (200)
- PUT /todos/{id} partial (200)
- PUT /todos/{id} no title (400)
- PUT /todos/{id} no amend id (400)

## DELETE Challenges

- [DELETE /todos id (200)](/apichallenges/solutions/delete/delete-todos-id-200)

## OPTIONS Challenges

- [OPTIONS /todos (200)](/apichallenges/solutions/options/options-todos-200)

## Accept Header Challenges

- [GET /todos (200) XML](/apichallenges/solutions/accept-header/get-todos-200-xml)
- [GET /todos (200) JSON](/apichallenges/solutions/accept-header/get-todos-200-json)
- [GET /todos (200) ANY](/apichallenges/solutions/accept-header/get-todos-200-any)
- [GET /todos (200) XML pref](/apichallenges/solutions/accept-header/get-todos-200-xml-pref)
- [GET /todos (200) no accept](/apichallenges/solutions/accept-header/get-todos-200-no-accept)
- [GET /todos (406)](/apichallenges/solutions/accept-header/get-todos-406)

## Content-Type Header Challenges

- [POST /todos XML](/apichallenges/solutions/content-type-header/post-todos-xml)
- [POST /todos JSON](/apichallenges/solutions/content-type-header/post-todos-json)
- [POST /todos (415)](/apichallenges/solutions/content-type-header/post-todos-415)

## Fancy a Break? Restore your session

- GET /challenger/guid (existing X-CHALLENGER)
- PUT /challenger/guid RESTORE
- PUT /challenger/guid CREATE
- GET /challenger/database/guid (200)
- PUT /challenger/database/guid (Update)

## Mix Accept and Content-Type Challenges

- [POST /todos XML to JSON](/apichallenges/solutions/mix-accept-content/post-xml-accept-json)
- [POST /todos JSON to XML](/apichallenges/solutions/mix-accept-content/post-json-accept-xml)

## Status Code Challenges

- [Solve the 405, 500, 501 and 204 Status Code Challenges](/apichallenges/solutions/status-codes/status-codes-405-500-501-204)
- DELETE /heartbeat (405)
- PATCH /heartbeat (500)
- TRACE /heartbeat (501)
- GET /heartbeat (204)

## HTTP Method Override Challenges

- POST /heartbeat as DELETE (405)
- POST /heartbeat as PATCH (500)
- POST /heartbeat as Trace (501)

## Authentication Challenges

- [POST /secret/token (401)](/apichallenges/solutions/authentication/post-secret-401)
- [POST /secret/token (201)](/apichallenges/solutions/authentication/post-secret-201)

## Authorization Challenges

- [GET /secret/note (403)](/apichallenges/solutions/authorization/get-secret-note-403)
- [GET /secret/note (401)](/apichallenges/solutions/authorization/get-secret-note-401)
- [GET /secret/note (200)](/apichallenges/solutions/authorization/get-secret-note-200)
- [POST /secret/note (200)](/apichallenges/solutions/authorization/post-secret-note-200)
- [POST /secret/note (401) && (403)](/apichallenges/solutions/authorization/post-secret-note-401-403)
- POST /secret/note (401)
- POST /secret/note (403)
- [GET && POST /secret/note (Bearer)](/apichallenges/solutions/authorization/get-post-secret-note-bearer)
- GET /secret/note (Bearer)
- POST /secret/note (Bearer)

## Miscellaneous Challenges

- DELETE /todos/{id} (200) all
- POST /todos (201) all
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
date: 2021-05-29T09:30:00Z
title: API Challenges Solution For - GET todos any 200
description: How to solve API challenge GET todos any 200 to accept the todos in default format.
---

# GET all the todos in default format

How to complete the challenge `GET /todos ANY (200)` to successfully GET all the todos in default format.

## GET /todos ANY (200)

> Issue a GET request on the `/todos` end point with an `Accept` header of `*/*` to receive results in Default format
- `GET` request will receive a response with all the todo items
- e.g. `GET /todos` to get all the todo items
- `200` is a success code, in this case it means the end point exists and the `todo items were returned
- `Accept` means that an `Accept` header was added to specify that the todos should be returned in **ANY** format i.e. the default from the server
- add the `X-CHALLENGER` header to track progress


## Basic Instructions

- Issue a `GET` request to end point "/todos"
- if running locally that endpoint would be
- `http://localhost:4567/todos`
- if running in the cloud that endpoint would be
- `https://apichallenges.herokuapp.com/todos`
- The request should have an `Accept` header specifying ANY format by using a value of `*/*`, our application defaults to JSON
- The request should have an `X-CHALLENGER` header to track challenge completion
- The response status code should be `200` when all the details are valid.
- Check the body of the message has JSON format data, which is the default from the server
- Check the `content-type` header in the response has `application/json`


## Example Request

~~~~~~~~
> GET /todos HTTP/1.1
> Host: apichallenges.herokuapp.com
> User-Agent: insomnia/2021.2.2
> X-CHALLENGER: x-challenger-guid
> Accept: */*
~~~~~~~~

## Example Response

~~~~~~~~
< HTTP/1.1 200 OK
< Connection: close
< Date: Sat, 29 May 2021 09:06:15 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: *
< X-Challenger: x-challenger-guid
< Server: Jetty(9.4.z-SNAPSHOT)
< Via: 1.1 vegur
~~~~~~~~

Example Response body:

```json
{
"todos": [
{
"id": 235,
"title": "pay invoices",
"doneStatus": false,
"description": ""
},
{
"id": 239,
"title": "tidy meeting room",
"doneStatus": false,
"description": ""
}
]
}
```


## Overview Video

{{<youtube-embed key="O4DhJ8Ohkk8">}}

[Patreon ad free version](https://www.patreon.com/posts/51830126)




Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
date: 2021-05-09T09:30:00Z
title: API Challenges Solution For - GET todos json 200
description: How to solve API challenge GET todos json 200 to accept the todos in json format.
---

# GET all the todos in JSON format

How to complete the challenge `GET /todos JSON (200)` to successfully GET all the todos in JSON format.

## GET /todos JSON (200)

> Issue a GET request on the `/todos` end point with an `Accept` header of `application/json` to receive results in JSON format
- `GET` request will receive a response with all the todo items
- e.g. `GET /todos` to get all the todo items
- `200` is a success code, in this case it means the end point exists and the `todo items were returned
- `Accept` means that an `Accept` header was added to specify that the todos should be returned in **JSON** format
- add the `X-CHALLENGER` header to track progress


## Basic Instructions

- Issue a `GET` request to end point "/todos"
- if running locally that endpoint would be
- `http://localhost:4567/todos`
- if running in the cloud that endpoint would be
- `https://apichallenges.herokuapp.com/todos`
- The request should have an `Accept` header specifying JSON format by using a value of `application/json`
- The request should have an `X-CHALLENGER` header to track challenge completion
- The response status code should be `200` when all the details are valid.
- Check the body of the message has JSON format data
- Check the `content-type` header in the response has `application/json`


## Example Request

~~~~~~~~
> GET /todos HTTP/1.1
> Host: apichallenges.herokuapp.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Accept: application/json
~~~~~~~~

## Example Response

~~~~~~~~
< HTTP/1.1 200 OK
< Connection: close
< Date: Sun, 09 May 2021 11:07:48 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: *
< X-Challenger: x-challenger-guid
< Server: Jetty(9.4.z-SNAPSHOT)
< Via: 1.1 vegur
~~~~~~~~

Example Response body:

```json
{
"todos": [
{
"id": 16,
"title": "process payroll",
"doneStatus": false,
"description": ""
},
{
"id": 15,
"title": "pay invoices",
"doneStatus": false,
"description": ""
}
]
}
```

## Overview Video

{{<youtube-embed key="79JTHiby2Qw">}}

[Patreon ad free version](https://www.patreon.com/posts/51045284)



Loading

0 comments on commit c1c2ab5

Please sign in to comment.