Step 1 : Define app settings
1-1 : Create app config file
1-2 : Define an entity
schemas
array1-3 : Config data storage
1-4 : Define an endpoint
Step 2 : Run the app
Step 3 : Contract with todo app
Add new task
Retrieve tasks
Creating a RESTful API
http
:adding more methods
The http endpoint has five routes:
The first is a POST method for sending Nolang scripts.
The second, at /add
, accepts a JSON body containing name and progress keys.
The /list
route retrieves a list of tasks via a GET request.
The /formSubmitTarget
route allows submission of an HTML form with the action set to /formSubmitTarget
, pay attention to using the bodyParser attribute.
/redirectMe
route shows if the response of a request contains redirect key, the request will be redirected to its value. For example if you call a method in request, that method can reply an object contains $$res
includes a redirect key.
Finally the /responseManipulate
route shows all options to how to manipulate the response of http using $$res
keyword. For more information see Express Response Methods.
from the browser or any js client, we can use the API like below:
Web Socket sample
Server Sent Events sample
Uploading files
file
or image
type properties in entities:config app
Uploading file from browser to server
command
property like below:After uploading file(s) and the command, the file will be stored in [upload-dir]/[entity's $id]/[id of new record]/[name of image filed] , for example ./uploads/entity3/2341/photo.png
In the database where data of the entity is stored, in the photo field, a json data will be saved containing these information: {fileName: file.name,
size: file.size,
ext: fileExt}
How to consider user roles
- Add
user
section in theapp.json config file, withauthenticate: true
- Have an entity containing users' info
- For any entity required to consider the user access rights, have
$$roles
in the entity definition - In scripts that are sent to app, add
user
information
1- In app.json config file
2- Define an entity for users' information
3- Add $$roles
in entity
4- User info in $$header.user
in Nolang scripts
jwt
is set in user
section of app config file, after sending the above script to the server, a token will be generated and returned. that token must be saved in the client side and used in next scripts like below:directRoles : true
is set in user
section of app config file, roles of users can be sent directly in script. It is not a secure way and must be used just in development not in production.