Johan Karlsson
Johan Karlsson

Reputation: 938

REST and validation of one field

I'm no expert in this so please tell me if I'm way off :)

I'm trying to define a REST service that handles accounts.

/Accounts/32  (GET to fetch one)
/Accounts     (GET to fetch all)

And so on...

However, in the sign up process, before an account is created, I would like to verify a couple of fields, like E-mail and ssn, async before the account is created.

How should I go about doing so? I just want to know if they exist in a combination but I shouldn't get a resource back since it's none of my business. :)

Is it valid to do something like this?

/Accounts?ssn=123&[email protected]&operation=verifyexistance

Thanks

// Johan

Upvotes: 1

Views: 58

Answers (2)

openai_sucks
openai_sucks

Reputation: 1273

I like Anas Salman's answer, which suggests the use of HEAD. That's the ideal method.

But I also think that GET is perfectly fine. You are requesting to get information about the resource (the /accounts collection).

GET /accounts?ssn=123&[email protected]

When /accounts sees a request in this format (a GET request with an SSN and email address provided), it has enough information to know to respond appropriately with an affirmative or negative.

The addition of an "operation" verb in the query string is the only unRESTFUL part of your example.

Upvotes: 2

Anas Salman
Anas Salman

Reputation: 372

Interesting question, for me I would prefer to do the following:

HEAD /accounts?ssn=123&[email protected]

if response status code is 200 then the resource exist on the server if response status code is 404 then the resource not available and you can continue with registration

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.

Upvotes: 4

Related Questions