SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
POST requests that were not recognized as RESTFul APIs are transferred to the host with SL_NETAPP_REQUEST_HTTP_POST as the request type. The user handler must parse the HTTP metadata, extract the resource name and any other fields of interest, and generate a response. The host may choose to respond immediately by filling all response fields in the handler. Alternatively, the host can fill the status field to pending and return, which means another part of the user application must complete the reception of the request using the sl_NetAppRecv API. Then it must use the sl_NetAppSend API to send a response. Figure 10-12 shows the data flow when the response is sent immediately.
Similarly to Figure 10-12, the following code receives acknowledgments for every POST request to the host with an HTTP 200 OK response:
void NetAppRequestHandler( SlNetAppRequest_t *pNetAppRequest,
SlNetAppResponse_t *pNetAppResponse)
{
extern _u16 gHandle;
switch(pNetAppRequest->Type)
{
case SL_NETAPP_REQUEST_HTTP_POST:
{
pNetAppResponse->Status = SL_NETAPP_HTTP_RESPONSE_200_OK;
pNetAppResponse->ResponseData.pMetadata = NULL;
pNetAppResponse->ResponseData.MetadataLen = 0;
pNetAppResponse->ResponseData.pPayload = NULL;
pNetAppResponse->ResponseData.PayloadLen = 0;
pNetAppResponse->ResponseData.Flags = 0;
}
break;
default:
/* GET/PUT/DELETE requests will reach here. */break;
}
}