Building APIs

Futuristic Backend Technology

Seagull provides you with a truly simple building block for building backend systems: API Classes. They are really easy to use and will transform into massively scalable nano-services, running as AWS Lambda functions. This allows you to skip configuring server instances, monitoring load or calculating fixed monthly costs.

This Guide will ... Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

seagull add api HelloWorld
1
2
3
4
5
6
7
8
9
10
import { API, Request, Response } from '@seagull/core'

export default class HelloWorld extends API {
  /**
   * This handle function executes your code. Return one of the following method invocations: 'text', 'json', 'redirect', 'missing', 'error'
   */
  async handle(request: Request): Promise<Response> {
    return this.text('hello world')
  }
}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

seagull add api HelloWorld --path /hello
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { API, Request, Response } from '@seagull/core'

export default class HelloWorld extends API {
  /**
   * The URL path where this API will be located. Skip for private functions like cronjobs. Example: '/greetings/{name}'
   */
  static path: string = '/hello'
  /**
   * This is the HTTP method / verb for the API. Defaults to 'GET'
   */
  static method: string = 'GET'

  /**
   * This handle function executes your code. Return one of the following method invocations: 'text', 'json', 'redirect', 'missing', 'error'
   */
  async handle(request: Request): Promise<Response> {
    return this.text('hello world')
  }
}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { API, Request, Response } from '@seagull/core'

export default class HelloWorld extends API {
  /**
   * The URL path where this API will be located. Skip for private functions like cronjobs. Example: '/greetings/{name}'
   */
  static path: string = '/hello'
  /**
   * This is the HTTP method / verb for the API. Defaults to 'GET'
   */
  static method: string = 'GET'

  /**
   * This handle function executes your code. Return one of the following method invocations: 'text', 'json', 'redirect', 'missing', 'error'
   */
  async handle(request: Request): Promise<Response> {
    const { name } = request.params
    return this.text(`hello, ${name}`)
  }
}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

seagull add api HelloService --path /greet --method POST
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { API, Request, Response } from '@seagull/core'

export default class HelloService extends API {
  /**
   * The URL path where this API will be located. Skip for private functions like cronjobs. Example: '/greetings/{name}'
   */
  static path: string = '/greet'
  /**
   * This is the HTTP method / verb for the API. Defaults to 'GET'
   */
  static method: string = 'POST'

  /**
   * This handle function executes your code. Return one of the following method invocations: 'text', 'json', 'redirect', 'missing', 'error'
   */
  async handle(request: Request): Promise<Response> {
    const { firstName, lastName } = request.body
    const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
    const FirstName = capitalize(firstName)
    const LastName = capitalize(lastName)
    const Message =`Greetings, ${FirstName} ${LastName}`
    return this.json({ FirstName, LastName, Message })
  }
}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto quasi quibusdam officiis ratione impedit nihil tenetur recusandae voluptas voluptatum, odit possimus dicta, vel nobis soluta fugiat non atque dignissimos aperiam.