Zeravla
Zeravla

Reputation: 173

REST equivalent for a isVerb kind of method (boolean response)

I am new to REST and have some trouble finding the proper RESTful url for an API.

I have an API that, given a word, returns a JSON with a boolean that indicates if the word is a verb or not. So in a not restful universe, this API would be a isVerb method. I am having trouble with finding a proper RESTful noun for the url of my API (as verbs are not allowed in REST).

I already have an API that given a string returns the verbs in that string (the actual GET /verbs) so the option myapi.com/verbs is not possible (and wouldn't be 100% right for my problem, as I am not getting verbs, but getting a boolean).

Any hints? Thanks a lot!

Upvotes: 2

Views: 2438

Answers (2)

Ming Chan
Ming Chan

Reputation: 1958

If I understand you correctly, there are two use-cases:

  • 1) Extracting verbs from a string and

  • 2) Test if a word is a verb.

Here is how I would decompose the problem:

A) You have two inputs, a string and a word; but both can be abstracted out just as an array of words,

a strings = [‘word1’, ‘word2’, …]

B) To think of “/verbs/” as a space for all verbs

Then the problem becomes to just get a set of verbs out of the ‘virtual’ verbs space in ‘/verbs/’ by providing inputs (a string of words).

The API to access '/verbs/'could be in two forms:

A) GET /verbs/?text=‘word’,…

Return: OK with the subset of text that are verb

Return: Not found

B) GET /verbs/{word}/

Return: OK with the ‘word’ if it is a verb

Return: Not found

Upvotes: 1

pWoz
pWoz

Reputation: 1679

In my opinion '/verbs' path is very good in this scenario. But if it already has been taken consider something similar, for example: '/verbsResource', '/versSet', ...

This service will return (for GET request):

  • status code HTTP 200 OK when given string is a verb;
  • status code HTTP 404 Not Found when given string is NOT a verb.

So there are no boolean values.

Upvotes: 0

Related Questions