How to filtering data from POST request body?

I want to remove the ability to filter by sensitive data in the query parameters. To do this, I changed the endpoint that retrieves the filtered data from GET to POST.

Before:

  public getUsers(pageRequest: PageRequest, filterRequest: FilterRequest, sortRequest: SortRequest): Observable<Response<User[]>> {
        const params: HttpParams = toHttpParams(pageRequest, filterRequest, sortRequest);
        return this.httpClient.get<Response<UserEntry[]>>('/users', { params: params });
    }

After:

  public getUsers(pageRequest: PageRequest, filterRequest: FilterRequest, sortRequest: SortRequest): Observable<Response<User[]>> {
        const body = {
            pageRequest: pageRequest,
            filterRequest: filterRequest,
            sortRequest: sortRequest
        };
        return this.httpClient.post<Response<User[]>>('/users', body);
    }

On the server side I changed the /users endpoint from GET to POST and it returns the data correctly, so it works fine.

However, I have a problem on the client side, namely, the user data in the list is returned correctly (so the endpoint works) but I have a problem with filtering the data, i.e. for example, applying a filter that only displays new users, etc.
In the GET method this worked fine, but after changing to POST the filters stopped working.

Perhaps by doing this the filtering should be moved from the query to the body? I just don’t know how I could do it properly?

    private getUsers(): void {
        this.loading = true;
        const requestParams = this.requestParamsService.getRequestParams({
                                                                             pageNumber: '1',
                                                                             pageSize: '10',
                                                                             sort: 'date, ASC'
                                                                         });
        const pageRequest = new PageRequest(requestParams.pagingAndSortingParams.pageNumber, requestParams.pagingAndSortingParams.pageSize);
        const sortRequest = new SortRequest(requestParams.pagingAndSortingParams.sort);
        const filterRequest = requestParams.filterRequest;
        this.usersService.getUsers(pageRequest, filterRequest, sortRequest)
            .subscribe({
                           next: response => {
                               const pagination = response.pagination;
                               const [ field, order ] = pagination.sort.replace(' ', '')
                                                                  .split(',');
                               this.tableMetadata = {
                                   first: pagination.currentPageNumber * pagination.pageSize - pagination.pageSize,
                                   rows: pagination.pageSize,
                                   sortField: field,
                                   sortOrder: order === 'ASC' ? 1 : -1
                               };
                               this.responseData = response.data;
                           },
                           error: () => {
                               this.responseData = [];
                               this.loading = false;
                           },
                           complete: () => {
                               this.applyTableSorting();
                               this.requestParamsService.refreshQueryParams({ selectedTab: UsersTabType[ this.currentTab ] });
                               this.loading = false;
                           }
                       });
    }
    public readParamsFromQuery(params: Params): void {
        if (Object.keys(params).length == 0) {
            return;
        }

        let pagingAndSortingParams: PagingAndSortingParams = null;
        let filterRequest: FilterRequest = null;
        Object.keys(params).forEach(paramKey => {
            switch (paramKey) {
                case 'pageNumber':
                case 'pageSize':
                case 'sort':
                    pagingAndSortingParams = { ...pagingAndSortingParams, [`${paramKey}`]: params[paramKey] };
                    break;
                case 'selectedTab':
                    break;
                default: {
                    const values = params[paramKey].split(',');
                    if (values.length > 1) {
                        filterRequest = { ...filterRequest, [`${paramKey}`]: values };
                    } else {
                        filterRequest = { ...filterRequest, [`${paramKey}`]: values[0] };
                    }

                    break;
                }
            }
        });
        const requestParams: RequestParamsMetadata = {
            pagingAndSortingParams: pagingAndSortingParams,
            filterRequest: filterRequest
        };
        if (!pagingAndSortingParams && !filterRequest) {
            return;
        }

        if (JSON.stringify(this._requestParams) !== JSON.stringify(requestParams)) {
            this._requestParams = requestParams;
            this.updateRequestPrams();
        }
    }

New contributor

user25675382 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật