C function to handle http request