typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
71.88k stars 6.93k forks source link

Can I search by property name? #779

Open RomaSto opened 6 years ago

RomaSto commented 6 years ago

I have data like: [ { "name": "Ondricka LLC", "id": "7257455862", "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg/2000px-Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg.png", "lastExecution": "2017-12-29T08:51:50.205Z", "duration": 63838, "locations": 17433, "link": "https://teagan.biz", "warnings": 81508, "errors": 76781, "status": "Disabled" }, { "name": "Ondr", "id": "7455943400", "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg/2000px-Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg.png", "lastExecution": "2017-08-10T05:49:20.775Z", "duration": 495, "locations": 54119, "link": "https://devonte.com", "warnings": 92119, "errors": 69269, "status": "Active" }, { "name": "Bahringer LLC", "id": "8781797582", "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg/2000px-Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg.png", "lastExecution": "2018-05-06T13:24:36.024Z", "duration": 28113, "locations": 81782, "link": "https://leanne.biz", "warnings": 79832, "errors": 56778, "status": "Active" }, { "name": "Oberbrunner LLC", "id": "3225738390", "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg/2000px-Mauritius_Road_Signs_-_Mandatory_Sign_-_Compulsory_Round-about.svg.png", "lastExecution": "2017-12-02T07:40:31.604Z", "duration": 85941, "locations": 55081, "link": "http://hudson.name", "warnings": 30265, "errors": 42681, "status": "Active" }, ]

Can json server search it by name property? If I give it "Ondr" it returns "Ondr", "Ondricka LLC"

lukehler commented 6 years ago

I had to wrap your data in an object and drop the trailing comma after Oberbrunner. I just used the cunningly-named { "stuff": <your array here> } in this case. With that in place, here's what I got:

Seems like it's working as expected and you can just use the name property (or any other property that you want) instead of full text search.