Skip to content

tdd-ai/SimpleTokenizerAPI.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Julia API Template - SimpleTokenizerAPI.jl

This repo contains an example of an API of SimpleTokenizer.jl in Julia.

The following project structure is recommended :

  • Auth module for authentication
  • Client module for client requests
  • Resource module for HTTP registrations and other resources
  • Model module for type definitions
  • Mapper module for database interactions
  • Service module for service functions

Environment file .env

This file will contain the path to packages file and other environment variables to be used in both the API package and Dockerfile.

Create your own version of the .env file and set the variables according to your application's required settings:

cp vars.env .env

Note that you must not share your own copy of .env file, since it might contain security related information (like authentication tokens).

Run directly

source .env
julia deploy/packagecompile.jl
julia --sysimage $LIB_PATH -e "SimpleTokenizerAPI.run()"

Build docker image and run

source .env && docker build --build-arg api_port=$API_PORT --build-arg auth_token=$AUTH_TOKEN --build-arg lib_path=$LIB_PATH -t simple_tokenizer.jl_api:v0.1 .
docker run -p $API_PORT:$API_PORT -d simple_tokenizer.jl_api:v0.1

Test API using cURL

if you are not in the same terminal window, run: source .env first.

curl -H "Auth-Token: "$AUTH_TOKEN -X POST -d '{"text":"this is some sentence. this is another sentence"}' http://localhost:$API_PORT/tokenize/
{"tokens":["this","is","some","sentence.","this","is","another","sentence"]}
curl -H "Auth-Token: "$AUTH_TOKEN -X POST -d '{"text":"this is some sentence. this is another sentence"}' http://localhost:$API_PORT/count-tokens/
{"count":8}
curl -H "Auth-Token: "$AUTH_TOKEN -X POST -d '{"text":"this is some sentence. this is another sentence"}' http://localhost:$API_PORT/get-unique-words/
{"unique-words":["another","this","is","sentence.","some","sentence"]}
curl -H "Auth-Token: "$AUTH_TOKEN  -X POST -d '{"text":"this is some sentence. this is another sentence"}' http://localhost:$API_PORT/not-existing-api/
"not found"

About

This repo contain an example of an API of a service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published