0
0

More than 1 year has passed since last update.

qiita apiを叩く。 その2

Last updated at Posted at 2022-01-06

概要

javascriptで、qiita apiを叩いてみた。
itemsをpostしてみた。

サンプルコード

var src = document.getElementById('src');
var prm = document.getElementById('prm');
var out = document.getElementById('out');
var endpoint = "https://qiita.com/api/v2/items";
function run() {
	var token = src.value;
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 201)
		{
			out.value = xhr.responseText;
		}
		else
		{
			//alert(xhr.readyState);
			//alert(xhr.status);
		}
	};
	xhr.open("POST", endpoint, true);
	xhr.setRequestHeader('Authorization', 'Bearer ' + token);
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.send(prm.value);
	//alert("ok");
}

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0