tahrir
tahrir copied to clipboard
Identifying the errors
Hey, I have done sample code for /identity and /message uri.. Is this the way we need to proceed?
Hello all , I wrote this variation which aims to respond on the type of request made ; If used using browser then it will return in html else if using curl on the type of request either json or html it would respond;
But it has no error but on running the server, it just shows the status " Not Found" Restlet Default page; Could anyone help me figure out what's going wrong?
Is there a way to check the type of the response which is expected along with the type of request?
Tejas: for each request, a specific response on expected. what exactly is expected is determined by the API that we wrote. Go check that document, it is king.
What I meant was for example in class TahrirRestlet in /message we've used if request.getmethod.getName.equals("Get") on the similar lines i was looking for a method similar to this to check for response for what kind of MediaType is expected along with the request. If the response is Html or Json. Presently we set the type of response as part of setEntity(response,Mediatype)
Well according to the API doc, when we receive a GET in /messages, we must return a JSON that looks like this:
{ "messages":[ { "author_pubkey":"...", "author_nick":"sanity", "message_id":124, "message_hash":"4z...E8", "content":"hi" }, { "author_pubkey":"...", "author_nick":"some_other_Guy", "message_id":534, "message_hash":"dsfgdfsgsdf", "content":"teeheehe" } ] }
So when we set the response, we just set the Mediatype to JSON. I don't see why we shouldn't do this. There's no method to check what the response should be, the requester doesn't give that to us, it just assumes we've read the API doc and have implemented correctly.
True!!! I was just trying out new stuffs with REST like chrome extension POSTMAN so was trying new thing with it. The above thing was just a example. Whatever we've done till now is exactly as per the API doc written. I was just exploring new things around the REST and Restlet.