55
661\. @ref ways_to_get_userver "Get userver".
77
8- 2\. Create new service with the following command (if you installed userver system-wide) :
8+ 2\. Create a new service project with the following command:
99
1010``` shell
11- userver-create-service myservice
11+ userver-create-service [--grpc] [--mongo] [--postgresql] myservice
1212```
1313
14- If you installed userver via CPM or as a git repository, call script from userver directory:
15- ``` shell
16- userver/scripts/userver-create-service myservice
17- ```
14+ This will create ` myservice ` dir, relative to the current working directory.
15+
16+ If you did not install userver system-wide and the command above is not found, see @ref service_templates.
17+
18+ To use additional userver libraries later, see @ref service_templates_libraries.
1819
19- If you want to enable gRPC, postgresql, or mongo in your service, use the following flags :
20+ 3 \. Build and test your service. Run in the service project root :
2021
2122``` shell
22- userver-create-service --grpc --mongo --postgresql myservice
23+ make build-debug && \
24+ make test-debug
2325```
2426
25- 3 \. Build and test your service. Run in the service repo root :
27+ 4 \. To get a feel for how the service runs without needing to set up full production environment, run :
2628
2729``` shell
28- make build-release && \
29- make test-release
30+ myservice$ make start-debug
3031```
3132
32- Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
33-
33+ Wait until the service starts, then try to send a request.
3434
35- ## Quick start for beginners (old way)
35+ ``` shell
36+ curl http://127.0.0.1:8080/hello? name=userver
37+ ```
3638
37- 1\. Press the "Use this template" button at the top right of the
38- [ GitHub template page] ( https://github.com/userver-framework/service_template ) .
39+ The answer should be something like this:
3940
40- @warning [ service_template] ( https://github.com/userver-framework/service_template ) has no databases and uses HTTP.
41- If you need gRPC or a database, please use other @ref service_templates "templates".
41+ ``` shell
42+ > curl http://127.0.0.1:8080/hello? name=userver
43+ Hello, userver!
44+ ```
4245
43- 2 \. Clone the service:
46+ 5 \. (Optional) Add the service project to Git :
4447
4548``` shell
46- git clone https://github.com/your-username/your-service. git && cd your-service
49+ myservice$ git init && git add . && git commit -m " Initial commit "
4750```
4851
49- 3\. @ref ways_to_get_userver "Get userver".
52+ Push it to GitHub
53+ (see [ its documentation] ( https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github#adding-a-local-repository-to-github-using-git ) ).
5054
51- 4 \. Build and start your service. Run in the service repo root:
55+ There are preconfigured GitHub CI checks that run ctest tests.
5256
53- ``` shell
54- make build-release && \
55- make start-release
56- ```
57+ Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
5758
58- During the build, you can make a coffee break until approximately the following output appears:
59+ ## Quick start for beginners (old way, pre userver 2.8)
5960
60- ``` shell
61- ====================================================================================================
62- Started service at http://localhost:8080/, configured monitor URL is http://localhost:-1/
63- ====================================================================================================
61+ @warning Service template repositories are deprecated, because possible sets of userver libraries to include cause
62+ an exponential growth in the number of wanted repositories. For userver 2.9 and later, use
63+ the @ref quick_start_for_beginners "service project generator script" instead.
6464
65- PASSED
66- [service-runner] Service started, use C-c to terminate
67- INFO < userver> Server is started
68- ...
69- DEBUG < userver> Accepted connection # 2/32768
70- DEBUG < userver> Incoming connection from ::ffff:127.0.0.1, fd 43
65+ 1\. Press the "Use this template" button at the top right of the appropriate service template repo page:
7166
72- ```
67+ | Link | Contains |
68+ | ------------------------------------------------------------------| ------------------------|
69+ | https://github.com/userver-framework/service_template | HTTP |
70+ | https://github.com/userver-framework/pg_service_template | HTTP, PostgreSQL |
71+ | https://github.com/userver-framework/pg_grpc_service_template | HTTP, PostgreSQL, gRPC |
72+ | https://github.com/userver-framework/mongo_grpc_service_template | HTTP, MongoDB, gRPC |
7373
74- 5 \. Try to send a request.
74+ 2 \. Clone the service:
7575
7676``` shell
77- curl http ://127.0.0.1:8080/hello ? name=userver
77+ git clone https ://github.com/your-username/your-service.git && cd your-service
7878```
7979
80- The answer should be something like this :
80+ 3 \. Give a proper name to your service and replace all the occurrences of " * service_template" string with that name :
8181
8282``` shell
83- > curl http://127.0.0.1:8080/hello? name=userver
84- Hello, userver!
83+ find . -not -path " ./third_party/*" -not -path " .git/*" -not -path ' ./build-*' -type f | xargs sed -i ' s/service_template/YOUR_SERVICE_NAME/g'
8584```
8685
87- Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
86+ 4\. @ref ways_to_get_userver "Get userver".
87+
88+ 5\. Build and test the service, see steps 3-4 from the @ref quick_start_for_beginners "updated instruction above".
8889
8990@anchor service_templates
9091## Service templates for userver based services
9192
92- There are ready to use service templates at GitHub :
93+ To create a new service project, run :
9394
94- | Link | Contains |
95- | ------------------------------------------------------------------| ------------------------|
96- | https://github.com/userver-framework/service_template | HTTP |
97- | https://github.com/userver-framework/pg_service_template | HTTP, PostgreSQL |
98- | https://github.com/userver-framework/pg_grpc_service_template | HTTP, PostgreSQL, gRPC |
99- | https://github.com/userver-framework/mongo_grpc_service_template | HTTP, MongoDB, gRPC |
95+ ``` shell
96+ userver-create-service [--grpc] [--mongo] [--postgresql] myservice
97+ ```
10098
101- To create a service:
99+ * Project directory will be ` myservice ` , relative to the current working directory;
100+ * service name will be the last segment of the path;
101+ * even without feature flags, the service only has some stubs for HTTP handlers.
102102
103- 1 . Press the "Use this template" button at the top right of the GitHub template page
104- 2 . Clone the service ` git clone your-service-repo && cd your-service-repo `
105- 3 . Give a proper name to your service and replace all the occurrences of "* service_template" string with that name.
106- 4 . Feel free to tweak, adjust or fully rewrite the source code of your service.
103+ If instead of installing userver you are planning to build userver as a subdirectory, call the script from userver directory:
104+
105+ ``` shell
106+ path/to/userver/scripts/userver-create-service myservice
107+ ```
108+
109+ If you use CPM to download userver, see @ref userver_cpm "CPM section".
107110
108111You'll need to @ref ways_to_get_userver "get userver" before proceeding with local development.
109112
@@ -246,9 +249,7 @@ Some advice:
246249# ## Downloading userver using CPM
247250
248251userver itself can be downloaded and built using CPM.
249- In fact, this is what
250- [download_userver()](https://github.com/userver-framework/service_template/blob/develop/cmake/DownloadUserver.cmake)
251- function does in @ref service_templates " service templates" by default.
252+ In fact, this is what `download_userver ()` function does in @ref service_templates " service templates" by default.
252253
253254` download_userver()` just calls ` CPMAddPackage` with some defaults, so you can pin userver ` VERSION` or ` GIT_TAG`
254255for reproducible builds.
@@ -258,6 +259,10 @@ When acquiring userver via CPM, you first need to install build dependencies. Th
258259* install @ref scripts/docs/en/userver/build/dependencies.md " build dependencies"
259260* or use base image of @ref docker_with_ubuntu_22_04
260261
262+ To use a @ref service_templates " service template" with CPM, run this script to get ` userver-create-service` command:
263+
264+ @ref service-template/userver-create-service.sh
265+
261266Make sure to @ref service_templates_presets " enable" the CMake options to build userver libraries you need,
262267then link to those libraries.
263268
@@ -480,3 +485,4 @@ The resulting binary should be 2-15% faster than without PGO, depending on the c
480485@htmlonly < /div> @endhtmlonly
481486
482487@example service-template/CMakeUserPresets.json.example
488+ @example service-template/userver-create-service.sh
0 commit comments