Normal
Quite the broad question you have there.I guess it really depends on what your desired outcome is. If it's a one off thing, and you don't really care (as long it's secure), then it really doesn't matter how you achieve it.However, if your goal is to create an API that is RESTful, and would be more familiar to your average developer, then there's room for improvement.Pre-requisites:HTTP Request MethodsHTTP Status CodesQuery StringAdditionally, I'd recommend installing a client like Postman, that will allow you to interact with your API, if you haven't already.Anyways, I assume the phone number comes from some table in the database? Let's assume it's the [ICODE]users[/ICODE] table.Here's what your HTTP request might look like:[CODE]GET /users?phone_number=8675309Host: example.comAuthorization: YOUR_AUTH_TOKEN[/CODE]Which would return something like this:[CODE="json"]{ "meta": { "total": 1 }, "items": [ { "id": 1, "name": "John Doe", "phone_number": "8675309" }, ],}[/CODE]So what this allows you to do is query for all [ICODE]users[/ICODE] with the specific phone number you're looking for, and can validate whether it has been used or not based on [ICODE]meta.total[/ICODE] in the response. Then if you have any other need for accessing [ICODE]users[/ICODE], you already have an endpoint setup. Also, you'll see that [ICODE]Authorization[/ICODE] would be sent as a [ICODE]header[/ICODE] in the HTTP request, which you validate server side, and if it passes, you'd serve the content. If the [ICODE]Authorization[/ICODE] header if invalid, you'd respond with a [ICODE]401[/ICODE] status code.Hopefully that's inline with what you're attempting to do, and gives you some direction.
Quite the broad question you have there.
I guess it really depends on what your desired outcome is. If it's a one off thing, and you don't really care (as long it's secure), then it really doesn't matter how you achieve it.
However, if your goal is to create an API that is RESTful, and would be more familiar to your average developer, then there's room for improvement.
Pre-requisites:
Additionally, I'd recommend installing a client like Postman, that will allow you to interact with your API, if you haven't already.
Anyways, I assume the phone number comes from some table in the database? Let's assume it's the [ICODE]users[/ICODE] table.
Here's what your HTTP request might look like:
[CODE]GET /users?phone_number=8675309
Host: example.com
Authorization: YOUR_AUTH_TOKEN
[/CODE]
Which would return something like this:
[CODE="json"]{
"meta": {
"total": 1
},
"items": [
{
"id": 1,
"name": "John Doe",
"phone_number": "8675309"
],
}[/CODE]
So what this allows you to do is query for all [ICODE]users[/ICODE] with the specific phone number you're looking for, and can validate whether it has been used or not based on [ICODE]meta.total[/ICODE] in the response. Then if you have any other need for accessing [ICODE]users[/ICODE], you already have an endpoint setup. Also, you'll see that [ICODE]Authorization[/ICODE] would be sent as a [ICODE]header[/ICODE] in the HTTP request, which you validate server side, and if it passes, you'd serve the content. If the [ICODE]Authorization[/ICODE] header if invalid, you'd respond with a [ICODE]401[/ICODE] status code.
Hopefully that's inline with what you're attempting to do, and gives you some direction.