Where should I put my dart files if they are the server side files of restful api providers?

StackOverflow https://stackoverflow.com/questions/17529407

Pergunta

I'm trying to use start to write some restful apis for clients.

The content is looking like:

import 'package:start/start.dart';
import 'myfile1.dart';
import 'myfile2.dart';
import 'myfile3.dart';
import 'myfile4.dart';

void main() {
start(public: 'web', port: 3000).then((Server app) {
    app.get('/').listen((request) {
      request.response
        .send('Hello, dart');
    });
    app.get('/aaa').listen(...);
    app.get('/bbb').listen(...);
    app.get('/ccc').listen(...);
    app.get('/ddd').listen(...);
  });
}    

Notice there are also some other dart files myfileN.dart in the same dir.

Where should I put them?

According to the dart project layout, there are several entry points:

bin
lib
web
example
test

But I don't know where should I put my dart files. Since this is not a library, it's just an server-side application, and is not a web app, not a test, not an example, and not a command-line script.

I think there should be a src to put my files, but there is not. How to solve this problem? Doesn't the standard layout doesn't design well?

Foi útil?

Solução 2

Many applications use third-party software.

Third-party software often organized as pluggable functionality.

Pluggable functionality often implemented not as independent executables but as linked libraries.

Also when you wrote application then you often divide it on different functionality.

The best way in this case (in Dart) put different functionality in different libraries. This simplify your life when you will be testing and maintain your application.

By convention libraries in Dart resides in 'lib' directory. Also implementation of libraries by convention must be located in 'lib/src' directory.

There may also be other possible explanations for this need. I just tried explain it to you as simple as possible.

Outras dicas

You can create an src within lib and put your files there.

If the files are executable, you can put them inside bin, or within a directory inside bin.

See the package layout conventions for details.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top