MCPcopy Index your code
hub / github.com/WP-API/node-wpapi / _httpPost

Function _httpPost

lib/http-transport.js:289–308  ·  view source on GitHub ↗

* 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 )

Source from the content-addressed store, hash-verified

287 * @returns {Promise} A promise to the results of the HTTP request
288 */
289function _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

Callers

nothing calls this directly

Calls 3

_authFunction · 0.85
_setHeadersFunction · 0.85
invokeAndPromisifyFunction · 0.85

Tested by

no test coverage detected