According to assessment's description, the system is designed in such a way that it can filter any field with any condition.
URL parameters is the most flexible and simple way to add basic/complicated filtering to REST APIs.
Using query string array for conditions benefits:
- Flexibility to implement any type of conditions.
- Ease of use for clients.
- Simple to parse on server side.
GET
/api/users
Retrieve all users' dataGET
/api/users?filters[]=name like ja%
Retrieve users names starts with 'ja'GET
/api/users?filters[]=name like ja%&filters[]=age <= 25
Retrieve users names starts with 'ja' and age less than or equal to 25GET
/api/users?filters[]=age > 10&filters[]=age <= 25
Retrieve users with age greater than 10 and age less than or equal to 25GET
/api/users?filters[]=name like %a%&filters[]=age>25&filters[]=relationship=Engaged
Retrieve users names contains 'a' and age greater than 25 that has Engaged relationship
Operator | Description |
---|---|
LIKE | Filter for a specified string pattern |
= | Equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
<> | Not equal to |
!= | Not equal to |
- Update User Model (migration, factory, seeder, unit test)
- Create Extra Models (migration, factory, seeder, unit test)
- Create Relation (unit test, diagram)
- Migrate and Seed the Database
- Implement Filterable Mechanism
- Add Controller and Route
- Manual Testing (outputs)
- Write Documentation (readme)