Skip to main content
Code Review

Return to Question

edited tags
Link
added 25 characters in body
Source Link

we have a RESTful API that includes an endpoint for search

apiserver/v5/search?q=[search text]

for any query, it passes it off to solr and returns the result like

{code:200,results:[{..},{...}]}

if q parameter is omitted, it returns:

{code:412,message:"parameter q is required"}

if q parameter is EMPTY, eg ?q= then it also returns 412: if q parameter is omitted, it returns:

{code:412,message:"parameter q is empty"}

The design is the the search PAGE with eg example.com/search?q= will show a default view and not make the query if it is empty, but instead just show a search box or default information.

My question is, Is it poor design or very non-standard to have the API return error on empty query? ie, does it make the API very unexpected/uncomfortable, or is it quite reasonable, to enforce that "you won't get results so you should be handling this in front end behavior"

Below is the full relevant code.

NOTE: this is the real code. searchsearch function handles all the validation and sanitation and other stuff and is outside the scope of the relevant code and question

<?php
require('search.php');
if(!isset($_GET['q'])
 echo '{code"code":412,message"message":"parameter q is required"}';
// should we do this to enforce they should handle front end?
if(empty($_GET['q']))
 echo '{code"code":412,message"message":"parameter q is empty"}';
echo search($_GET['q']);

we have a RESTful API that includes an endpoint for search

apiserver/v5/search?q=[search text]

for any query, it passes it off to solr and returns the result like

{code:200,results:[{..},{...}]}

if q parameter is omitted, it returns:

{code:412,message:"parameter q is required"}

if q parameter is EMPTY, eg ?q= then it also returns 412: if q parameter is omitted, it returns:

{code:412,message:"parameter q is empty"}

The design is the the search PAGE with eg example.com/search?q= will show a default view and not make the query if it is empty, but instead just show a search box or default information.

My question is, Is it poor design or very non-standard to have the API return error on empty query? ie, does it make the API very unexpected/uncomfortable, or is it quite reasonable, to enforce that "you won't get results so you should be handling this in front end behavior"

Below is the full relevant code.

NOTE: this is the real code. search function handles all the validation and sanitation and other stuff and is outside the scope of the relevant code and question

<?php
require('search.php');
if(!isset($_GET['q'])
 echo '{code:412,message:"parameter q is required"}';
// should we do this to enforce they should handle front end?
if(empty($_GET['q']))
 echo '{code:412,message:"parameter q is empty"}';
echo search($_GET['q']);

we have a RESTful API that includes an endpoint for search

apiserver/v5/search?q=[search text]

for any query, it passes it off to solr and returns the result like

{code:200,results:[{..},{...}]}

if q parameter is omitted, it returns:

{code:412,message:"parameter q is required"}

if q parameter is EMPTY, eg ?q= then it also returns 412: if q parameter is omitted, it returns:

{code:412,message:"parameter q is empty"}

The design is the the search PAGE with eg example.com/search?q= will show a default view and not make the query if it is empty, but instead just show a search box or default information.

My question is, Is it poor design or very non-standard to have the API return error on empty query? ie, does it make the API very unexpected/uncomfortable, or is it quite reasonable, to enforce that "you won't get results so you should be handling this in front end behavior"

Below is the relevant code.

NOTE: search function handles all the validation and sanitation and other stuff and is outside the scope of the relevant code and question

<?php
require('search.php');
if(!isset($_GET['q'])
 echo '{"code":412,"message":"parameter q is required"}';
// should we do this to enforce they should handle front end?
if(empty($_GET['q']))
 echo '{"code":412,"message":"parameter q is empty"}';
echo search($_GET['q']);
edited tags
Link
Post Reopened by Sᴀᴍ Onᴇᴌᴀ
remove rude comment
Source Link
Loading
edited tags
Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141
Loading
added 311 characters in body
Added to review
Source Link
Loading
added 311 characters in body
Source Link
Loading
Post Closed as "Not suitable for this site" by Vogel612, Sᴀᴍ Onᴇᴌᴀ
Source Link
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /