Basic usage of Vovk Controller and Service.
1export default class BasicService {
2 /**
3 * Return a greeting
4 */
5 static getHello() {
6 return { greeting: 'Hello world!' };
7 }
8}
1export default class BasicService {
2 /**
3 * Return a greeting
4 */
5 static getHello() {
6 return { greeting: 'Hello world!' };
7 }
8}
1export default class BasicService {
2 /**
3 * Return a greeting
4 */
5 static getHello() {
6 return { greeting: 'Hello world!' };
7 }
8}
1export default class BasicService {
2 /**
3 * Return a greeting
4 */
5 static getHello() {
6 return { greeting: 'Hello world!' };
7 }
8}
1import { get, prefix } from 'vovk';
2import BasicService from './BasicService';
3
4@prefix('basic-with-service')
5export default class BasicControllerWithService {
6 @get('greeting', { cors: true })
7 static getHello() {
8 return BasicService.getHello();
9 }
10}
1import { get, prefix } from 'vovk';
2import BasicService from './BasicService';
3
4@prefix('basic-with-service')
5export default class BasicControllerWithService {
6 @get('greeting', { cors: true })
7 static getHello() {
8 return BasicService.getHello();
9 }
10}
1import { get, prefix } from 'vovk';
2import BasicService from './BasicService';
3
4@prefix('basic-with-service')
5export default class BasicControllerWithService {
6 @get('greeting', { cors: true })
7 static getHello() {
8 return BasicService.getHello();
9 }
10}
1import { get, prefix } from 'vovk';
2import BasicService from './BasicService';
3
4@prefix('basic-with-service')
5export default class BasicControllerWithService {
6 @get('greeting', { cors: true })
7 static getHello() {
8 return BasicService.getHello();
9 }
10}
1'use client';
2import { useState } from 'react';
3import { BasicControllerWithService } from 'vovk-client';
4import type { VovkReturnType } from 'vovk';
5
6export default function BasicExampleWithService() {
7 const [serverResponse, setServerResponse] = useState<VovkReturnType<typeof BasicControllerWithService.getHello>>();
8
9 return (
10 <>
11 <button
12 onClick={async () => {
13 const response = await BasicControllerWithService.getHello();
14 setServerResponse(response);
15 }}
16 >
17 Get Greeting from Server
18 </button>
19 <div>{serverResponse?.greeting}</div>
20 </>
21 );
22}
1'use client';
2import { useState } from 'react';
3import { BasicControllerWithService } from 'vovk-client';
4import type { VovkReturnType } from 'vovk';
5
6export default function BasicExampleWithService() {
7 const [serverResponse, setServerResponse] = useState<VovkReturnType<typeof BasicControllerWithService.getHello>>();
8
9 return (
10 <>
11 <button
12 onClick={async () => {
13 const response = await BasicControllerWithService.getHello();
14 setServerResponse(response);
15 }}
16 >
17 Get Greeting from Server
18 </button>
19 <div>{serverResponse?.greeting}</div>
20 </>
21 );
22}
1'use client';
2import { useState } from 'react';
3import { BasicControllerWithService } from 'vovk-client';
4import type { VovkReturnType } from 'vovk';
5
6export default function BasicExampleWithService() {
7 const [serverResponse, setServerResponse] = useState<VovkReturnType<typeof BasicControllerWithService.getHello>>();
8
9 return (
10 <>
11 <button
12 onClick={async () => {
13 const response = await BasicControllerWithService.getHello();
14 setServerResponse(response);
15 }}
16 >
17 Get Greeting from Server
18 </button>
19 <div>{serverResponse?.greeting}</div>
20 </>
21 );
22}
1'use client';
2import { useState } from 'react';
3import { BasicControllerWithService } from 'vovk-client';
4import type { VovkReturnType } from 'vovk';
5
6export default function BasicExampleWithService() {
7 const [serverResponse, setServerResponse] = useState<VovkReturnType<typeof BasicControllerWithService.getHello>>();
8
9 return (
10 <>
11 <button
12 onClick={async () => {
13 const response = await BasicControllerWithService.getHello();
14 setServerResponse(response);
15 }}
16 >
17 Get Greeting from Server
18 </button>
19 <div>{serverResponse?.greeting}</div>
20 </>
21 );
22}