Copy to Clipboard CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://www.narro.co/api/v1/articles");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "accept: application/json");
headers = curl_slist_append(headers, "content-type: application/json");
headers = curl_slist_append(headers, "authorization: Bearer <access_token>");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}");
CURLcode ret = curl_easy_perform(hnd);
Copy to Clipboard (require '[clj-http.client :as client])
(client/post "https://www.narro.co/api/v1/articles" {:headers {:authorization "Bearer <access_token>"}
:content-type :json
:form-params {:url "https://www.narro.co/faq"
:title "My Optional, Custom Title"}
:accept :json})
Copy to Clipboard var client = new RestClient("https://www.narro.co/api/v1/articles");
var request = new RestRequest(Method.POST);
request.AddHeader("accept", "application/json");
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer <access_token>");
request.AddParameter("undefined", "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Copy to Clipboard package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://www.narro.co/api/v1/articles"
payload := strings.NewReader("{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("authorization", "Bearer <access_token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Copy to Clipboard POST /api/v1/articles HTTP/1.1
Authorization: Bearer <access_token>
Host: www.narro.co
Content-Length: 73
{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}
Copy to Clipboard OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}");
Request request = new Request.Builder()
.url("https://www.narro.co/api/v1/articles")
.post(body)
.addHeader("authorization", "Bearer <access_token>")
.build();
Response response = client.newCall(request).execute();
Copy to Clipboard HttpResponse<String> response = Unirest.post("https://www.narro.co/api/v1/articles")
.header("authorization", "Bearer <access_token>")
.body("{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}")
.asString();
Copy to Clipboard var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.narro.co/api/v1/articles",
"method": "POST",
"headers": {
"authorization": "Bearer <access_token>"
},
"processData": false,
"data": "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
Copy to Clipboard fetch("https://www.narro.co/api/v1/articles", {
"method": "POST",
"headers": {
"authorization": "Bearer <access_token>"
},
"body": {
"url": "https://www.narro.co/faq",
"title": "My Optional, Custom Title"
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
});
Copy to Clipboard var data = JSON.stringify({
"url": "https://www.narro.co/faq",
"title": "My Optional, Custom Title"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://www.narro.co/api/v1/articles");
xhr.setRequestHeader("authorization", "Bearer <access_token>");
xhr.send(data);
Copy to Clipboard var http = require("https");
var options = {
"method": "POST",
"hostname": "www.narro.co",
"port": null,
"path": "/api/v1/articles",
"headers": {
"authorization": "Bearer <access_token>"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({url: 'https://www.narro.co/faq', title: 'My Optional, Custom Title'}));
req.end();
Copy to Clipboard var request = require("request");
var options = {
method: 'POST',
url: 'https://www.narro.co/api/v1/articles',
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: 'Bearer <access_token>'
},
body: {url: 'https://www.narro.co/faq', title: 'My Optional, Custom Title'},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Copy to Clipboard var unirest = require("unirest");
var req = unirest("POST", "https://www.narro.co/api/v1/articles");
req.headers({
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer <access_token>"
});
req.type("json");
req.send({
"url": "https://www.narro.co/faq",
"title": "My Optional, Custom Title"
});
req.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.body);
});
Copy to Clipboard #import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"authorization": @"Bearer <access_token>" };
NSDictionary *parameters = @{ @"url": @"https://www.narro.co/faq",
@"title": @"My Optional, Custom Title" };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.narro.co/api/v1/articles"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
Copy to Clipboard open Cohttp_lwt_unix
open Cohttp
open Lwt
let uri = Uri.of_string "https://www.narro.co/api/v1/articles" in
let headers = Header.add (Header.init ()) "authorization" "Bearer <access_token>" in
let body = Cohttp_lwt_body.of_string "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}" in
Client.call ~headers ~body `POST uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)
Copy to Clipboard <?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.narro.co/api/v1/articles",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}",
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"authorization: Bearer <access_token>",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Copy to Clipboard <?php
$request = new HttpRequest();
$request->setUrl('https://www.narro.co/api/v1/articles');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'accept' => 'application/json',
'content-type' => 'application/json',
'authorization' => 'Bearer <access_token>'
));
$request->setBody('{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
Copy to Clipboard <?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->append('{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}');
$request->setRequestUrl('https://www.narro.co/api/v1/articles');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array(
'accept' => 'application/json',
'content-type' => 'application/json',
'authorization' => 'Bearer <access_token>'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Copy to Clipboard $headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("content-type", "application/json")
$headers.Add("authorization", "Bearer <access_token>")
$response = Invoke-WebRequest -Uri 'https://www.narro.co/api/v1/articles' -Method POST -Headers $headers -ContentType 'undefined' -Body '{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}'
Copy to Clipboard $headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("content-type", "application/json")
$headers.Add("authorization", "Bearer <access_token>")
$response = Invoke-RestMethod -Uri 'https://www.narro.co/api/v1/articles' -Method POST -Headers $headers -ContentType 'undefined' -Body '{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}'
Copy to Clipboard import http.client
conn = http.client.HTTPSConnection("www.narro.co")
payload = "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}"
headers = { 'authorization': "Bearer <access_token>" }
conn.request("POST", "/api/v1/articles", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Copy to Clipboard import requests
url = "https://www.narro.co/api/v1/articles"
payload = "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}"
headers = {'authorization': 'Bearer <access_token>'}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
Copy to Clipboard require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://www.narro.co/api/v1/articles")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer <access_token>'
request.body = "{\"url\": \"https://www.narro.co/faq\", \"title\": \"My Optional, Custom Title\"}"
response = http.request(request)
puts response.read_body
Copy to Clipboard curl --request POST \
--url https://www.narro.co/api/v1/articles \
--header 'accept: application/json' \
--header 'authorization: Bearer <access_token>' \
--header 'content-type: application/json' \
--data '{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}'
Copy to Clipboard echo '{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}' | \
http POST https://www.narro.co/api/v1/articles \
authorization:'Bearer <access_token>'
Copy to Clipboard wget --quiet \
--method POST \
--header 'authorization: Bearer <access_token>' \
--body-data '{"url": "https://www.narro.co/faq", "title": "My Optional, Custom Title"}' \
--output-document \
- https://www.narro.co/api/v1/articles
Copy to Clipboard import Foundation
let headers = ["authorization": "Bearer <access_token>"]
let parameters = [
"url": "https://www.narro.co/faq",
"title": "My Optional, Custom Title"
] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://www.narro.co/api/v1/articles")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()