简体   繁体   English

是否可以在不了解移动应用程序前端的情况下构建 REST API

[英]is it possible to built REST API without knowing about frontend for mobiles apps

This could be a silly question but I want to confirm about it.这可能是一个愚蠢的问题,但我想确认一下。 I am a backend Laravel developer and have created my website.我是后端 Laravel 开发人员并创建了我的网站。 Now I want to create mobile mobile apps but have no knowledge of front-end.现在我想创建移动应用程序,但对前端一无所知。

Due to lockdown situations I want to use this time to create the backend API for my apps.由于锁定情况,我想利用这段时间为我的应用程序创建后端 API。 Now I want to know is it ok or a normal practice to create APIs without knowing anything about front end.现在我想知道在不了解前端的情况下创建 API 是否可以或正常做法。 (Like is it possible that I just create all the endpoints now that are throwing data in JSON and then the front-end developer will use them to integrate in the front-end? Thanks (就像我现在是否有可能创建所有在 JSON 中抛出数据的端点,然后前端开发人员将使用它们集成到前端?谢谢

PS: I dont know how the app front-end will look like but I know what data will be needed in each page/view. PS:我不知道应用程序前端会是什么样子,但我知道每个页面/视图中需要哪些数据。

I think you can do this easily with graphql.我认为您可以使用 graphql 轻松做到这一点。

A Frontend dev and also beginners with Apollo in the frontend can easily introspect and build the stuff.前端开发人员以及前端使用 Apollo 的初学者可以轻松自省和构建这些东西。

If you can choose your Frontend stack there is no problem with rest either.如果您可以选择前端堆栈,那么 rest 也没有问题。

I always do the Frontend first approach.我总是做前端优先的方法。 Mocking the data for graphql types and building the api later seems to me the best workflow ever. Mocking graphql 类型的数据和构建 api 后来在我看来是有史以来最好的工作流程。

See ya.再见。 Much fun with your project你的项目很有趣

Yes it is possible very possible to do that it would be nice is the API is well documented using postman or swagger for a better experience when frontend engineers want to integrate是的,很有可能这样做会很好的是 API 使用 postman 或 swagger 进行了详细记录,以便在前端工程师想要集成时获得更好的体验

Many API's in the world today are never consumed by a browser or app on the frontend, sure it can make life easier knowing why you are building it.当今世界上的许多 API 从未被前端的浏览器或应用程序使用过,确保它可以让生活更轻松地了解您构建它的原因。

But at the end of the day, a good API is simple and easy to understand.但归根结底,一个好的 API 简单易懂。 It just allows a developer to fetch data from a system but normally with some idea about each type of request.它只允许开发人员从系统中获取数据,但通常对每种类型的请求都有一些了解。

For example, if you had an API for a university the endpoints could be as follows:例如,如果您有大学的 API,则端点可能如下所示:

/pupils => Get/Sets pupil data.  
/teachers => Get/Sets teacher data.  
/classes => Get/Sets class subjects and references ID's of both Pupils and Teachers.

So if you wanted all the Pupils in a given class you would query the /classes endpoint and then for each Pupil ID you would query the /pupil endpoint.因此,如果您想要给定 class 中的所有 Pupils,您将查询/classes端点,然后对于每个 Pupil ID,您将查询/pupil端点。

Sometimes not having a frontend makes the API even more generic because you might think differently when you do not have a frontend.有时没有前端会使 API 更加通用,因为当您没有前端时,您可能会有不同的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM