Skip to content

Instantly share code, notes, and snippets.

@jweisman jweisman/Program.cs
Last active May 1, 2018

What would you like to do?
Refit for Alma APIs
using Newtonsoft.Json;
using Refit;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace refitalma
[Headers("Accept: application/json")]
public interface IAlmaApi
Task<AlmaUser> GetUser(string userName, [Header("Authorization")] string authorization);
public class AlmaUser
[JsonProperty(PropertyName = "first_name")]
public string firstName {get; set;}
[JsonProperty(PropertyName = "last_name")]
public string lastName {get; set;}
class Program
public static string authHeader =
"apikey " + Environment.GetEnvironmentVariable("ALMA_APIKEY");
public static async Task Main(string[] args)
var almaApi = RestService.For<IAlmaApi>("");
var user = await almaApi.GetUser(args[0], authHeader);
String.Format("Successfully retrieved user: {0} ({1} {2})\n",
args[0], user.firstName, user.lastName)

This comment has been minimized.

Copy link
Owner Author

jweisman commented May 1, 2018

To use:

dotnet new console
dotnet add package refit
wget -O Program.cs
dotnet run {user}

You may need to add <LangVersion>7.1</LangVersion> to the <PropertyGroup> in the .csproj.

See this blog for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.