* Invoke an HTTP "POST" request against the provided endpoint * @method post * @async * @param {WPRequest} wpreq A WPRequest query object * @param {Object} data The data for the POST request * @param {Function} [callback] A callback to invoke with the results of the POST request * @returns {Pr
( wpreq, data, callback )
| 287 | * @returns {Promise} A promise to the results of the HTTP request |
| 288 | */ |
| 289 | function _httpPost( wpreq, data, callback ) { |
| 290 | checkMethodSupport( 'post', wpreq ); |
| 291 | const url = wpreq.toString(); |
| 292 | data = data || {}; |
| 293 | let request = _auth( agent.post( url ), wpreq._options, true ); |
| 294 | request = _setHeaders( request, wpreq._options ); |
| 295 | |
| 296 | if ( wpreq._attachment ) { |
| 297 | // Data must be form-encoded alongside image attachment |
| 298 | request = objectReduce( |
| 299 | data, |
| 300 | ( req, value, key ) => req.field( key, value ), |
| 301 | request.attach( 'file', wpreq._attachment, wpreq._attachmentName ) |
| 302 | ); |
| 303 | } else { |
| 304 | request = request.send( data ); |
| 305 | } |
| 306 | |
| 307 | return invokeAndPromisify( request, callback, returnBody.bind( null, wpreq ) ); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * @method put |
nothing calls this directly
no test coverage detected