D
D
driverx182018-07-18 23:31:37
RESTful API
driverx18, 2018-07-18 23:31:37

I want to make an API, where do I start?

I want to make rest api (php + mysql), I have no experience in creating api at all. Let's say there is a mobile phone that will communicate with the server through the api, and the goal is to make a good, rest api.
The questions are as follows:
1) is it worth doing api using some kind of framework, or from scratch?
2) is it necessary to allocate a separate server for the api, or just call the daddy in the project api, and put all the files associated with it there?
3) good examples, literature, who can advise what. When I enter rest api php, a couple of lessons are given, but this is not quite what I need) I need various best practices

Answer the question

In order to leave comments, you need to log in

6 answer(s)
P
Philipp, 2018-07-19
@zoonman

You should start with API design. Take https://swagger.io/ and sketch everything you need.
Swagger allows you to combine routing, documentation and call examples into a single whole.
In addition, it allows you to generate stubs for different programming languages ​​and frameworks.
In principle, you can find a significant number of integrations for different frameworks.
In general, APIs are best done with the help of frameworks, since they already implement trivial security, authentication and authorization aspects. You can use microframeworks like Slim . You can even generate a route for it using the Swagger generator .
There are 6 principles in REST, beautifully laid out in the Wiki . There is nothing complicated or special about REST. It's just an add-on to the standard HTTP protocol. That is why there are no special lessons. Learn how HTTP works and you'll understand how the web in general and REST in particular work.
Concerning the separate server for API. There are many different approaches. Recently, serverless applications have become more and more relevant . Serverless architecture fits perfectly into REST. But I think it's too early and complicated for you. Too many to start.
It is most logical to keep the project in a mono-repository, if it is not large. If you don't know exactly how big it will be, then you can break the project into components and use Composer todependency management (I advise you to read this page in its entirety from cover to cover).
Regarding best practices, there is a very good resource https://12factor.net/ru/
It is generally used for all applications.
Remember: the first pancake is always lumpy. Read all the resources I have provided for you. They have many links to others, walk around them, take a closer look. Write the first version of the API the way you feel comfortable. Try to apply the practices from the articles.
You need experience and you won't get it until you do something yourself. You can spend a year reading and still end up where you started. And another person will write an API on his knee in a week, and then rewrite it 20 times in a year and he will tell you 10 times more than what you learned in a year.
Dare!

N
nozzy, 2018-07-18
@nozzy

https://lumen.laravel.com/

A
Andrey K, 2018-07-19
@kuftachev

Judging by your question, you are still far from creating an API, if the goal is commercial, it is better to turn to professionals.
If for yourself, then of course you need to first master some kind of framework, moreover, any of the main ones will offer a good solution for the API.
"Is it necessary to allocate a separate server for api, or just name a daddy in the project api, and put all the files associated with it there?"... Honestly, it's still early, the Front Controller pattern is in the blood of every web developer.

S
sdfsdfertdfd, 2018-07-19
@sdfsdfertdfd

No need to reinvent the wheel.
Yuzay ready-made cases - best practice.
It is necessary to offend every novice inventor.
It's too early for you to invent api - at first, use someone else's and don't stick your head out, a very smart one was found here.
The initiative is strictly punishable.
Everything should be standard and replaceable - this is the sacred meaning of the industry.

D
Dmi3ii, 2018-07-19
@Dmi3ii

I am a beginner, but I did it on laravel (for growth). For my tasks, it was not difficult, I quickly "driven" into the base. The network is full of tourtorials and videos on this topic. Install Insomnia or Postman to send requests and test your api.

T
ThunderCat, 2018-07-19
@ThunderCat

It seems that today all the main frameworks have api interfaces? Or am I missing something? IMHO, take a ready-made debugged engine and quickly and accurately raise the api - best practice on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question