0.1.8 • Published 1 month ago

roxterjs v0.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

Generic badge Generic badge

Status da api

  • Estável em produção
  • Ultima versão 2024-04-02
  • Versão atualizada v0.1.8

Novidades

# .env.test
$ ROXTER_MODE = "dev"|"prod" #default -> dev. Obrigatório mudar p/ "prod" em ambiente de produção.
$ ROXTER_PORT = 3333 #default -> porta de entrada (não obrigatório)
$ ROXTER_HOSTNAME = "localhost" #default (não obrigatório)
$ ROXTER_FILE_PATH = "./" #default -> __root pasta onde o arquivo app.routes.js será criado (não obrigatório)
$ ROXTER_FILE_ROUTES = "app.routes.js" #default -> nome_do_arquivo onde as rotas serão salvas (não obrigatório)
$ ROXTER_TIMEOUT = 10000 #default -> tempo limite de espera para resposta do serviço (não obrigatório)
$ ROXTER_CPUS = 0 #default -> detalhes no texto abaixo...

ROXTER_CPUS

Primeiros passos (exemplo):

# Crie um novo package.json
$ npm init -y
# npm ou yarn
$ npm i roxterjs
# app.js
  • root_projeto
    • app.js
    • package.json
    • README.md
    • src/
      • routes/
      • controller/
      • services/
# app.js
import Roxter from "roxterjs";
const roxter = await Roxter('./src/routes'); # <-caminho-> './src/routes'

# A função abaixo irá construir as rotas e iniciar o servidor
roxter.Start();

Criando uma rota:

  • root_projeto
    • app.js
    • package.json
    • README.md
    • src/
      • routes/
        • api/
          • view/
# http://localhost:3333/api/view
  • root_projeto
    • app.js
    • package.json
    • README.md
    • src/
      • routes/
        • api/
          • view/
            • get.js
# http://localhost:3333/api/view
# __root/src/routes/api/view/get.js

export default async function App({ res }){
    return res.end(JSON.stringfy({
        name: "RoxterJs",
        partner: "Roxter.Xteezer",
        address: "São Paulo - SP"
    }))
}
# Teste cURL:
$ curl -X GET http://localhost:3333/api/view

Recebendo uma parâmetros

# __root/src/routes/api/view/[id]/get.js

export default async function App({ res, keys }){
    const { id } = await keys;
    return res.end(`Sua chave é ${id}`);
}
# Teste cURL:
$ curl -X GET http://localhost:3333/api/view/1234

Recebendo querys

# __root/src/routes/api/view/[id]/get.js

export default async function App({ res, keys, params }){
    const { color } = await params;
    const { id } = await keys;
    return res.end(`Sua chave é ${id}, sua cor é ${color}`);
}
# Teste cURL:
$ curl -X GET http://localhost:3333/api/view/1234?color=azul

Recebendo um body

  • root_projeto
    • app.js
    • package.json
    • README.md
    • src/
      • routes/
        • api/
          • view/
            • ...
        • data/
          • dong/
            • post.js
# http://localhost:3333/data/dong
# __root/src/routes/data/dong/post.js

export default async function App({ res, body }){
    const { id } = await body;
    return res.end(`Sua chave é ${id}`);
}
# Teste cURL:
$ curl -X POST http://localhost:3333/data/dong -d '{"id":"191919"}'

Adicionando Resposta ao Header (setHeader)

# app.js
import Roxter from "roxterjs";
const roxter = await Roxter('./src/routes'); 

# Adicione como parâmetro Start({ params })
roxter.Start({
    setHeaders:[
        { name: "Access-Control-Allow-Origin", value: "*" },
        { name: "Access-Control-Allow-Methods", value: "GET, OPTIONS, POST, PUT" },
        { name: "Access-Control-Allow-Headers", value: "Access-Control-Allow-Headers, Origin, X-Requested-With, Content-Type, Accept, Authorization" }
    ]
});

🎲 Github

# Clone este repositório
$ git clone https://github.com/packrd/roxterjs.git

🛠 Tecnologias

As seguintes ferramentas foram usadas na construção do projeto:

Colaboradores

:1st_place_medal: @rodrigo.buttura

0.1.8

1 month ago

0.1.7

1 month ago

0.1.6

1 month ago

0.1.4

1 month ago

0.1.5

1 month ago

0.1.0

1 month ago

0.1.2

1 month ago

0.1.1

1 month ago

0.1.3

1 month ago

0.0.19

4 months ago

0.0.16

12 months ago

0.0.17

12 months ago

0.0.18

9 months ago

0.0.15

12 months ago

0.0.14

12 months ago

0.0.13

12 months ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago