Last active
August 29, 2015 13:56
-
-
Save gildo/8959667 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JS Generico | |
var request = new XMLHttpRequest(); | |
request.open('POST', 'http://staging.dropis.com', true); | |
request.send({"titolo": "macchina", ...}); | |
request.onload = function() { | |
if (request.status >= 200 && request.status < 400){ | |
// Success! | |
resp = request.responseText | |
} else { | |
// Errore | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://staging.dropis.com/api/0.1/ads'; | |
$data = array('title' => 'Titolo annuncio', 'location' => 'Roma ecc', ...); | |
$options = array( | |
'http' => array( | |
'header' => "Authorization: Bearer TUO-TOKEN", | |
'method' => 'POST', | |
'content' => http_build_query($data), | |
), | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
$data = json_decode($result, TRUE); | |
var_dump($data); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
url = "https://staging.dropis.com" | |
data = {'name': 'Alice', 'description': 'Libro', ...} | |
headers = {'Authorization': 'Bearer TUO-TOKEN'} | |
r = requests.post(url, data=json.dumps(data), headers=headers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uri = URI.parse("https://staging.dropis.com") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new("/api/0.1/ads") | |
request.add_field('Authorization', 'Bearer TUO-TOKEN') | |
request.body = {'name' => "nome Ad", 'description' => "Descrizione"... | |
response = JSON.parse(http.request(request)) | |
if response.status == 201 | |
puts response.body["data"] | |
else | |
puts response.body["error"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment