C
C#2y ago
Dusty

✅ Refit / RestLess API SDK Structure

Hey! How do I structure an SDK for my API? Let's say I have 2 resources: Users and Groups. I could use Refit or RestLess to create an interface which wraps the CRUD operations on both resources. However if I add more resources (which I do have) to the interface it gets messy. Is there a way to structure my API SDK like this?
public interface IMyApi
{
public IMyUsersApi Users { get; }
public IMyGroupsApi Groups { get; }
}
public interface IMyApi
{
public IMyUsersApi Users { get; }
public IMyGroupsApi Groups { get; }
}
Where IMyUsersApi and IMyGroupsApi would contain all CRUD operations for their resource.
5 Replies
Dusty
DustyOP2y ago
Anyone?
canton7
canton72y ago
What's your problem? Can't you do just that -- have one class which contains a Refit interface for users, and one for groups?
Dusty
DustyOP2y ago
Can you? I haven't seen documention about it. I've seen others having one big interface having all methods for every endpoint inside it
canton7
canton72y ago
You can just create a class? No need to get Refit involved there
public class MyApi : IMyApi
{
public IMyUsersApi Users { get; } = RestClient.For<IMyUsersApi>();
...
}
public class MyApi : IMyApi
{
public IMyUsersApi Users { get; } = RestClient.For<IMyUsersApi>();
...
}
(or whatever the refit syntax is)
Dusty
DustyOP2y ago
Oh I see Wow that's actually really simple Didn't think of that somehow You really saved me from a lot of headaches😂
Want results from more Discord servers?
Add your server