/users/123 => /users/#{nil} => /users/
if ($limit < 1 || $limit > 100) {
$limit = 100;
}
Don't let an unpaginated endpoint be a DDoS vector.
But, restrict what people can include.
Come on folks, it's free.
Go to letsencrypt.org
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected."
}
}
🙋 Hi, I'm a human and I have no idea what this means!
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected."
}
}
Oh I'm missing the 'filter' parameter?
Needed to add &mine=true
to URL...
🤔 😫
if (beresp.status == 429) {
set beresp.ttl = 0s;
}
def get_something(id)
response = JSON.parse(client.get('/api/something/'+id))
if response['RESPONSE']['CODE'] == "SUCCESS"
return response
elsif response['RESPONSE']['CODE'] == 'NOT FOUND'
return response
else
message = response['RESPONSE']['APIERROR']
raise SomeError, "Error from third-party API: #{message}."
end
end
def get_something(id)
response = JSON.parse(client.get('/api/something/'+id))
if response['RESPONSE']['CODE'] == "SUCCESS"
return response
elsif response['RESPONSE']['CODE'] == 'NOT FOUND'
return response
else
message = response['RESPONSE']['APIERROR']
raise SomeError, "Error from third-party API: #{message}."
end
rescue JSON::ParserError => e
raise HttpServerError, "Service returned invalid JSON data"
end
def get_something(id)
response = JSON.parse(client.get('/api/something/'+id))
if response.nil?
raise HttpServerError, "Service returned an empty response"
end
# ... success or fail
rescue JSON::ParserError => e
raise HttpServerError, "Service returned invalid JSON data"
end
def get_something(id)
response = JSON.parse(client.get('/api/something/'+id))
if response.nil?
raise HttpServerError, "Service returned an empty response"
end
unless response['RESPONSE'] && response['RESPONSE']['CODE']
raise HttpServerError, "Service returned an unexpected response: #{response}"
end
# ... success or fail
rescue JSON::ParserError => e
raise HttpServerError, "Service returned invalid JSON data"
end
The UPS API is so sparsely documented I'm having to actually send parcels to see what sort of data I get for specific situations.
— Dan Harper (@DanHarper7) June 30, 2016
Learn how to build docs: bit.ly/api-doc-video