views:

71

answers:

3

I have heard that http is a nice way to design my own protocol. although i can design a binary protocol, i would prefer to follow the HTTP standard to design my protocol. basically the flow of the application is that with the request the client sends some parameter strings to the server, the server sends the response string to the application. this procedure continues several times, before the connection thread terminates.

i am using java servlets for the above. how should the client send the HTTP parameters so that parsing is easy at the server.

Get /a HTTP/1.1
Host: localhost

??? what comes here
+3  A: 

??? what comes here

Since that is a GET request, nothing.

I'd suggest using querystring parameters, then you can access them using ServletRequest.getParameterNames(), getParameterValues(), getParameterMap() etc.

So, your request line would take the form:

GET /a?x=1&y=1 HTTP/1.1

since this is the standard way of passing parameter data, other clients, such as web browsers, will be able to use your service easily.

This assumes that the operation does not cause side-effects on the server. If it does then you should be using a POST, PUT or DELETE request depending on the exact nature of the operation.

HTTP Made Really Easy is a useful document since, at least initially, the HTTP Spec can be a bit daunting.

Andy
The parameters may be long strings, so will this be good option
iamrohitbanga
thanks for pointing out that with get i don't send any data.may be i'll send data in the content portion of a post request.
iamrohitbanga
Yes -- you are right, very long URLs are not generally a good idea and there is no limit on the amount of data you can POST so that is probably a better approach. Its worth remembering that if you POST data in query string format and use a Content-Type header of application/x-www-form-urlencoded you can still use the servlet APIs to access the parameters.
Andy
+1  A: 

What you're designing is a data exchange format, not a protocol really.

So the question is, really, what sort of data do you want to send? To answer that, you need to consider who is receiving it. If it's yourself, then just keep it simple.

Noon Silk
i want to know the standard for data exchange format using HTTP.
iamrohitbanga
People generally use XML formats; there are literally hundreds and no real standards (because a single standard doesn't make sense; there is different types of data for different producers/consumers). Who are you trying to integrate with?
Noon Silk
cool mine is right now an application from ground up. so i might work out an xml message for the content of post request.by the way i want to reuse the same thread for some request response sequences, i.e., a session. seems reasonable with HTTP/1.1 right?
iamrohitbanga
+2  A: 

Why not base your protocol on something that already exists for example SOAP?

MarkJ
do web services have an inherent performance overhead. i wanted to expose the functionality using a rest web service as an additional feature, but build a fast client app based on my protocol.
iamrohitbanga
XML certainly seems like a slow, flabby format to me - but I'm no expert on web services, maybe someone else can answer this question?
MarkJ