Site icon Hip-Hop Website Design and Development

Greatest strategy to retrieve knowledge in customized api prolonged from wp-api

I’ve prolonged WP API plugin to supply an API which might course of paperwork.

Routes

public perform register_routes($routes)
{
    $documents_routes = array(
        '/v1/paperwork' => array(
            array(array($this, 'create_document'), WP_JSON_Server::CREATABLE),
        )
    );
    $new_routes = array_merge($routes, $documents_routes);
    return $new_routes;
}

callback perform

public perform create_document($knowledge, $_files = null){

    if(!empty($_files)) {
        // course of file
    }


    // the right way to retrieve 
}

Request

POST /api/v1/paperwork/ HTTP/1.1
Host: localhost
Cache-Management: no-cache
Postman-Token: d5277e1c-12ac-309a-034f-135173b7c7f2
Content material-Kind: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="doc_id"

3268360
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="file"; filename="PINS REST API Documentation v1.2.doc"
Content material-Kind: utility/msword


----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="case_reference"

EN0102234
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="creator"

Ghazanfar
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="stage"

1
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="class"

Utility
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="kind"

Doc
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content material-Disposition: form-data; title="description"

That is check doc
----WebKitFormBoundary7MA4YWxkTrZu0gW

The Downside

I’ve some properties resembling doc_id, case_reference, description, creator, dimension and so forth which might be handed to the api together with the file.

Now the issue is I need to have the ability to retrieve all knowledge if content-type:form-data is used. What’s the easiest way to retrieve all handed knowledge within the callback perform effectively?