libexpress 0.0.1
Express Server Framework in C
Loading...
Searching...
No Matches
Data Structures | Functions
req.h File Reference

This contains all the request related material. More...

#include <libhmap/hmap.h>
#include <libqueue/queue.h>

Go to the source code of this file.

Data Structures

struct  req_t
 Request made by client. More...
 

Functions

req_tparse_req (char *req_str, int size)
 Parses the HTTP request string sent by client. More...
 
char * get_req_body (req_t *req)
 Get the body of request. More...
 
char * get_req_header (req_t *req, const char *header)
 Get a particular header from the request. More...
 
char * get_req_method (req_t *req)
 Get the method of the request. More...
 
char * get_req_param (req_t *req, const char *param)
 Get the value of a particular request path parameter. More...
 
char * get_req_path (req_t *req)
 Get the path of the request. More...
 
char * get_req_query (req_t *req, const char *query)
 Get a particular query from the request. More...
 

Detailed Description

This contains all the request related material.

Author
Saurav Pal (resyfer)
Bug:
No known bugs

Function Documentation

◆ get_req_body()

char * get_req_body ( req_t req)

Get the body of request.

Parameters
reqRequest
Returns
char* Body

◆ get_req_header()

char * get_req_header ( req_t req,
const char *  header 
)

Get a particular header from the request.

Parameters
reqRequest
headerHeader key
Returns
char* Header value

◆ get_req_method()

char * get_req_method ( req_t req)

Get the method of the request.

Parameters
reqRequest
Returns
char* Method

◆ get_req_param()

char * get_req_param ( req_t req,
const char *  param 
)

Get the value of a particular request path parameter.

The key (param) is set according to the route you're calling this function in. If the route is for path /hello/:id/world, then something like /hello/abcd/world will populate the param "id" with the value "abcd".

Parameters
reqRequest
paramName of the param, as used by the route.
Returns
char*

◆ get_req_path()

char * get_req_path ( req_t req)

Get the path of the request.

It gives the path requested by the client, minus any queries.

If the request by client is for /hello?search=world&foo=bar then the path is /hello

Parameters
reqRequest
Returns
char* Path

◆ get_req_query()

char * get_req_query ( req_t req,
const char *  query 
)

Get a particular query from the request.

If the request by client is for /hello?search=world&foo=bar then the queries are as follows:

search = world foo = bar

in the form of key = value

Parameters
req
query
Returns
char*

◆ parse_req()

req_t * parse_req ( char *  req_str,
int  size 
)

Parses the HTTP request string sent by client.

It parses the HTTP request string sent by the client and gives a req_t Request that contains all the information from the request in a meaningful manner.

Parameters
req_strHTTP Request String of the client
sizeNo. of bytes (string length) of the request string
Returns
req_t* Request