你如何在 Meteor 中制作 REST API 并上传文件 [英] How do you make a REST API and upload files in Meteor
问题描述
REST API 是什么?是否已经有办法为服务器上的 API 定义一些路由和逻辑?我认为这是当今必备的功能.
What is about a REST API? Is there already a way to define some routes and logic for the API on the server? I think this is nowadays a must-have feature.
文件上传也是如此.使用 express 框架,我已经可以非常轻松地处理上传.我如何在 Meteor 中做到这一点?文档对此一无所知.那么是否有一些计划来实施它?还是已经有办法了?
And the same with File-Uploads. With express framework I can already handle uploads really easy. How do I do this in Meteor? The documentation says nothing about it. So are there some plans to implement it? Or is there already a way?
推荐答案
至于 REST 去:Meteor 还没有提供支持的 API 来从您的应用程序提供 HTTP 服务.这是有意为之:在不久的将来,您的应用服务器很可能不仅仅是一个直接为最终用户提供服务的单个进程,而是一个代理层后面的可任意并行化的服务.因此,我们需要提供一个受支持的 API 来响应 HTTP 请求(例如,REST),以便在这种设置下继续工作.
As far as REST goes: Meteor doesn't yet provide a supported API for serving HTTP from your application. This is intentional: in the not-too-distant future, your application server is likely to not be just a single process directly serving end users, but an arbitrarily parallelizable service behind a proxy tier. So we'll need to provide a supported API for responded to HTTP requests (for example, REST) that continues to work in such a setting.
如果您现在确实需要接受直接的 HTTP REST 请求,请查看 packages/accounts-oauth-helper/oauth_server.js
如何使用 __meteor_bootstrap__.app
连接到 Connect 中间件框架.这暂时有效,但我们不保证 Meteor 将始终由 Connect 提供支持 :)
If you really need to accept direct HTTP REST requests now, take a peek at how packages/accounts-oauth-helper/oauth_server.js
uses __meteor_bootstrap__.app
to hook into the Connect middleware framework. This will work for now, but we don't promise that Meteor will always be powered by Connect :)
支持 REST 端点位于 Meteor 的路线图.
Supporting REST endpoints is on Meteor's roadmap.
文件上传也是如此(二进制类型指的是).
So is file uploads (that's what binary type refers to).
这篇关于你如何在 Meteor 中制作 REST API 并上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!