Code Monkey home page Code Monkey logo

deno-oak-api-server-sample's Introduction

deno-oak-api-server-sample

This code is api server on 'Deno'.
This api server use oak middleware framework.

Usage

Set env

BASIC_SECRET = [Basic auth secret]
SALT = [ Salt used when hashing]
DATA_BASE_FILE = [Database filename]
LOG_FILE = [Log filename]

Execution

# Create SQLite File.
> deno task db-create

# Create migrate from nessie.
> deno task db-migrate

# Register client info.
> deno task add-client --id hogehoge --secret hogehogehoge

# Start server.
> deno task dev

client request

# Request to token endpoint. 
> curl -s -H 'Authorization:Basic [Basic auth secret]' -XPOST  --data-urlencode 'client_id=[Client id]' -d 'client_secret=[Client Secret]' -d 'grant_type=client_credentials' http://0.0.0.0:8080/oauth2/token | jq .
{
  "access_token": "hogehogehogehogehogehogehogehoge",
  "token_type": "bearer",
  "expires_in": 3600
}

# Post data. 
> curl -s -H 'Authorization:Bearer hogehogehogehogehogehogehogehoge' -H "Content-Type: application/json"  -XPOST -d '{"text":"Sample Text"}' http://0.0.0.0:8080/resource/posts | jq .
{
  "status": true
}

# Get data.
> curl -s -H 'Authorization:Bearer hogehogehogehogehogehogehogehoge' http://0.0.0.0:8080/resource/posts | jq .
[
  {
    "id": 1,
    "clientId": "hogehoge",
    "text": "Sample Text",
    "createdAt": "2022-05-28 16:46:37",
    "updatedAt": "2022-05-28 16:46:37"
  }
]

# Delete data.
> curl -s -H 'Authorization:Bearer hogehogehogehogehogehogehogehoge' -H "Content-Type: application/json"  -XDELETE -d '{"id":"1"}' http://0.0.0.0:8080/resource/posts | jq .

deno-oak-api-server-sample's People

Contributors

octo8080x avatar

Stargazers

辻 修一 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.