Jump to content

Deleting an episode using the c# ApiClient


Recommended Posts

Posted (edited)

Hi,

I am building a wpf application, where you can manage all your tv shows and episodes.

 

I'd appreciate guidance how to proceed regarding how to delete tv episodes where I have a handle to the selected episode id's, using the c# ApiClient.

I cannot see that there are any public delete methods available in the c# ApiClient, so I'm thinking about using the Swagger libraryservice "delete items" function by using the c# method GetApiUrl("/items/"+ episodeId). Would that be a good approach? 

 

Or maybe there are easier ways.

 

Thanks

Edited by joggs
Posted

It will need to be added if it's not already there. Or could just send a request to the url using getapiurl. Pull requests are welcome. Thanks.

Posted

It will need to be added if it's not already there. Or could just send a request to the url using getapiurl. Pull requests are welcome. Thanks.

 

I was successful deleting the episode.

 

There is a private DeleteAsync method in the ApiClient class that works well for my usecase. I created my own apiClient class and derived from the original one, adding the following method(copied from the baseclass):

 
public async Task<T> DeleteAsync<T>(string url, CancellationToken cancellationToken = default(CancellationToken)) where T : class
        {
            url = AddDataFormat(url);

            using (var stream = await HttpClient.SendAsync(new HttpRequest
            {
                Url = url,
                CancellationToken = cancellationToken,
                RequestHeaders = HttpHeaders,
                Method = "DELETE"

            }).ConfigureAwait(false))
            {
                return DeserializeFromStream<T>(stream);
            }
        }

And I called it by using

var url = ApiClientHandler.GetApiClient().GetApiUrl($"Items/{episodeId}");
            var response= await ApiClientHandler.GetApiClient().DeleteAsync<EmptyRequestResult>(url);

(ApiClientHandler.GetApiClient() is my own singleton code..)

Posted

Great, thanks for the info!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...