How to complete the challenge POST /todos XML
The content-type should match the data in the request. In this case we will send a POST request to create a todo item with body and response in XML format.
POST /todos XML
To create and amend items in a REST API we usually use a POST request. POST requests are defined as 'partial' requests in that they don't need to have all the fields, but they need to have enough fields to be valid for the request.
Issue a POST request on the
/todosend point to create a todo using Content-Typeapplication/xml, and Accepting only XML ie. Accept header ofapplication/xml
For this challenge we issue a request with an accept header specifying XML and we will send the message as XML so we set the content-type header as well.
POSTrequest means we will send information in the body of the message- e.g.
POST /todossends to the todos endpoint
- e.g.
create a todomeans that we will not include a todo id, so a new todo is createdContent-Typeapplication/xmlmeans set thecontent-typeheader toapplication/xmlAccept headerofapplication/xmlmeans set theacceptheader toapplication/xml- the body of the message will have to be a valid todo item, and we can see the format in the documentation, or by issuing a
GETrequest on the/todosendpoint - add the
X-CHALLENGERheader to track progress - we know it has been created when we receive a
201response - the body of the response should contain the full details of the
todocreated
Basic Instructions
- First issue a
GETrequest on "/todos" with anacceptheader ofapplication/xmlto see the format of a todo in XML format- or read the documentation at /docs
- copy a todo from the response to edit as payload for the
POSTmessage
- Issue a
POSTrequest to end point "/todos"- if running locally that endpoint would be
https://apichallenges.herokuapp.com/todos
- if running locally that endpoint would be
- The request should have an
Acceptheader with the valueapplication/xml - The request should have an
Content-Typeheader with the valueapplication/xml - Use the
todothat you copied from theGETrequest, remembering to remove theidbecause when we create a todo, it will be issued with anidautomatically
We only need to use the minimum details, but could add a description if we wanted.
<todo>
<doneStatus>true</doneStatus>
<title>file paperwork today</title>
</todo>
- The request should have an
X-CHALLENGERheader to track challenge completion - The response status code should be
201when all the details are valid. - Check the body of the response has XML formatted 'todo' response
- this will contain the full details of the todo we created
- Check the
content-typeheader in the response hasapplication/xmlmatching the requested accept format
Additional Exercises
- you might want to experiment with adding additional fields like 'description', what happens if you miss out fields?
- check the
Locationheader has the endpoint we can use to retrieve the todo, issue aGETon that endpoint to retrieve the details of the todo
Example Request
> POST /todos HTTP/1.1
> Host: apichallenges.herokuapp.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/xml
> Accept: application/xml
> Content-Length: 93
| <todo>
| <doneStatus>true</doneStatus>
| <title>file paperwork today</title>
| </todo>
Example Response
< HTTP/1.1 201 Created
< Connection: close
< Date: Sat, 17 Jul 2021 13:14:28 GMT
< Content-Type: application/xml
< Location: todos/226
< 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:
<todo>
<doneStatus>true</doneStatus>
<description/>
<id>226</id>
<title>file paperwork today</title>
</todo>