How to create a REST API with LIKE criteria?

I am developing a REST API and have an entity for "people":

GET http://localhost/api/people

Returns a list of all people in the system

GET http://localhost/api/people/1

Returns the person with identifier 1.

GET http://localhost/api/people?forename=john&surname=smith

It returns all people with matching first and last names, but I have one more requirement. What is the cleanest / best way to allow API users to retrieve all the people whose name begins with "jo", for example.

I have seen some APIs do this like:

GET http://localhost/api/people?forename=jo~&surname=smith

where tilde means "fuzzy" match. On the other hand, I saw that it is implemented with completely different criteria, for example.

GET http://localhost/api/people?forename-startswith=jo&surname=smith

which seems a bit cumbersome given that I might have a -response, -supported, -soundslike (for some soundex match).

- , , API REST, .

+5
4

AFAIK, RESTful. , ( - , - DSL). API . , API - . - REST.

, , OData​​strong > . OData REST, REST- . , , REST -.

, , , API , - DSL (, forenameStartsWith, forename-startswith).

, , OData.

+1

IMHO , -endswith -contains .. , REST API , (DB xml ..)

PHP... , SlimFramework - , .

+4

OData, . , , REST.

OData $expand $filter. $ " ", , URI:

http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=tolower(CompanyName) eq 'foobar' &select=FirstName,LastName&$orderby=Name desc

, SQL, , ( , ).

+3

Both examples use query parameters for filtering. I don’t think it matters what these query parameters call or the wildcard syntax is used.

Both approaches are equal to RESTFul.

0
source

All Articles