8.1.0 • Published 4 months ago

@adaskothebeast/http-params-processor v8.1.0

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

HttpParamsProcessor

Stores complex input parameters in Angular HttpParams for invoking GET to .net core web api. HttpParams in angular collects parameters then in case of get call in translates it to proper url. That url in backend side can be automatically converted to instance of class or simple type.

Usage sample

```javascript
    const complexParams: ComplexParams = {
      arr: [
        {
          id: '1',
          innerArr: [
            {
              id: '1.1',
              text: 'first first',
            },
            {
              id: '1.2',
              text: 'first second',
            },
          ],
        },
        {
          id: '2',
          innerArr: [
            {
              id: '2.1',
              text: 'second first',
            },
            {
              id: '2.2',
              text: 'second second',
            },
          ],
        },
      ],
    };

    @Injectable(
        { providedIn: 'root' }
    )
    export class WebApiService {
        constructor (
          @Inject(HttpClient) protected http: HttpClient,
          @Optional() @Inject(API_BASE_URL) protected baseUrl?: string,
          @Inject(HttpParamsProcessorService) protected processor: HttpParamsProcessorService) {
        }

        public get endpointServiceUrl(): string {
            if (this.baseUrl) {
                return this.baseUrl.endsWith('/') ? this.baseUrl + 'api/endpoint' : this.baseUrl + '/' + 'api/endpoint';
            } else {
                return 'api/endpoint';
            }
        }

        public getByQuery(query: ComplexParams): Observable<SomeDto> {
            const httpParams: HttpParams = this.processor.process('p', query);

            const headers = new HttpHeaders()
                .set('Accept', 'application/json')
                .set('If-Modified-Since', '0');

            return this.http.get<ResultDto>(
                this.endpointServiceUrl,
                {
                    headers: headers,
                    params: httpParams
                });
        }
    }
```

Part of url generated from above

    .../api/endpoint?p.arr%5B0%5D.id=1&p.arr%5B0%5D.innerArr%5B0%5D.id=1.1&p.arr%5B0%5D.innerArr%5B0%5D.text=first%20first&p.arr%5B0%5D.innerArr%5B1%5D.id=1.2&p.arr%5B0%5D.innerArr%5B1%5D.text=first%20second&p.arr%5B1%5D.id=2&p.arr%5B1%5D.innerArr%5B0%5D.id=2.1&p.arr%5B1%5D.innerArr%5B0%5D.text=second%20first&p.arr%5B1%5D.innerArr%5B1%5D.id=2.2&p.arr%5B1%5D.innerArr%5B1%5D.text=second%20second'
8.1.0

4 months ago

8.0.0

6 months ago

7.0.1

7 months ago

7.0.0

9 months ago

6.0.0

1 year ago

5.0.0

2 years ago

4.0.0

2 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago