0

I'm trying to create a JSON API that will return an array of JSON results matching specific search criteria. It will always be searching one specific content type, but will need to match custom fields for specific search terms. I will be passing a term to match a given field, for example:

/api/my-content-type?first_name=bob&term_a=my+term&another_field=search+term+here

The response from this needs to be an array of JSON objects containing the fields for that given content type.

I've seen many modules for this, but don't seem to see any that allow searching by field. Is this something I would need to implement custom? If so, what is the best module and/or method to start from?

Im not sure if I should be using a Search API, Services, one of the many REST JSON API Modules, etc.

  • I think my question is different, as I am not looking for generic search results, I need to search a specific content type, and match multiple terms against specific fields – Ryan Dec 12 '15 at 2:04
  • Searching for all the nodes or just for nodes of a specific content type is not different, with the exception that in that latter case you need to filter for content type; still, producing the JSON output is done in the same way. – kiamlaluno Dec 12 '15 at 16:35
  • My question was not directed completely towards creating JSON output. That part is easy enough. I wish people would be helpful rather than just mark this as a duplicate of another question that does not address the issues or questions that I raised in the original question. I ended up creating a custom module, as the Services module (indicated in the "duplicate" question) I didn't see how to make it fit the requirements listed above. Help per my question would have been appreciated. – Ryan Dec 15 '15 at 17:04
  • If not as duplicate, this question could have been closed as off-topic (we don't recommend modules), primarily opinion-based (what is best for you could not be _best for somebody else), or too broad (Im not sure if I should be using a Search API, Services, one of the many REST JSON API Modules, etc.; I've seen many modules for this, but don't seem to see any that allow searching by field. Is this something I would need to implement custom?). – kiamlaluno Dec 15 '15 at 17:15
  • Stack Exchange sites are community involved. In this case, 4 users thought the question should have been closed. If other users think it is wrongly closed, they can vote to re-open it. – kiamlaluno Dec 15 '15 at 17:18
1

I've seen many modules for this, but don't seem to see any that allow searching by field.

There are many modules which provide this feature, not necessarily out of the box, but with some customization.

I would say, the best module to start with this would be Restful.
I have personally used it for a similar use case for building the service endpoints which could be filtered using specific field values, and it work charms!
The documentation seems to have improved a lot since the last time I've seen it!

There are other modules present which help you create custom endpoint too. However, the ease of building such filterable endpoint is good with Restful as per my experience.

  • Thank you for the explanation AjitS. I ended up building a custom module that used EntityFieldQuery to search and return the data as JSON. This suites my needs, but as I'm trying to find out the proper way to handle this in Drupal, could you explain what you mean by customizing the module? Do you modify the module code itself, or is there a way to extend or customize the module otherwise (like through another module without modifying the exiting module)? I'm not familiar with this so even if you could point me in the direction of that, it would be appreciated. Thanks! – Ryan Dec 15 '15 at 17:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.