Exemple #1
0
        public PostsRequestModel(EPostsRequestType requestType)
        {
            ApiPath = "/api/v3/posts";
            Method  = ERestCommands.GET;

            RequestType = requestType;
        }
Exemple #2
0
        public async void Send(HttpClient client, string parameters, CancellationTokenSource tokenSource, ERestCommands method)
        {
            HttpResponseMessage response = null;

            switch (method)
            {
            case ERestCommands.GET:
                response = await RestCommand(() => client.GetAsync(client.BaseAddress, tokenSource.Token));

                break;

            case ERestCommands.POST:
                response = await RestCommand(() => client.PostAsync(client.BaseAddress, new StringContent(parameters, Encoding.UTF8, DAL.RestHeaderValues.ContentType), tokenSource.Token));

                break;

            case ERestCommands.DELETE:
                response = await RestCommand(() => client.DeleteAsync(client.BaseAddress, tokenSource.Token));

                break;

            case ERestCommands.PUT:
                response = await RestCommand(() => client.PutAsync(client.BaseAddress, new StringContent(parameters, Encoding.UTF8, DAL.RestHeaderValues.ContentType), tokenSource.Token));

                break;

            default:
                throw new WebException("Wrong REST command!");
            }

            OnMessage?.Invoke(response);
        }