Skip to content

Instantly share code, notes, and snippets.

@edqwerty1
edqwerty1 / asyncFetch.js
Created September 18, 2018 08:33
JS fetch async examples with error handling and comparison to promise.
// Old
function handleErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
// GET
fetch(`/myAPI/GetMethod?param=${this.param}`, {
var ids = @"1,2
3
asf
4 5";
Regex rx = new Regex(@"(\d+)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection matches = rx.Matches(ids);
var listIds = new List<int>();
foreach (Match match in matches)
public static class WebApiHelpers
{
public static string ToJson(Object model)
{
var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
return JsonConvert.SerializeObject(model, serializerSettings);
}