If you want to create a project, which can be scallable
/easy to maintain
/api-first approach
/loosely coople with UI
, then your first choice will be choosing Sangjog framework.
To start development you have use Sangjog-cli framework. Sangjog-cli will help you to develop Sangjog App easily. This framework is perfect for working with a large team at the same time.
- API First Approach
- Best for
SPA
- Simple Config control for
HTTP and HTTPS enabling
Strict Structural
Framework- Sangjog Project is built on
Typescript
Object oriented
andtype safe
project- Spring(JAVA framework)/Angular like
Annotation based
Project and API configuration - By default, Project
configuration data
in.env file
Modular
structureModules
are the entry of the ApplicationAPI Controllers
folder and classesAPI services
folder and classesDB Oparations
folder and classesDB Connection
folder and classesHTTP Syncronus Interceptors
like middlewire- Single point
Async Authentication and Authorization
service instance for every request Singletone of controller, service, db-oparator, db-connection and httpInterceptor
classes by default.Versioning of API
is the required rule for SangjogStrict folder structure
which will help the multiple team to work on a same project easily.- Seperate
UI Folder
which is configurable - Developers can work in parallel
- Reduce the cost of app development
- Reduce the risk of failure
- Taken less time
Sangjog requires Node.js v12+ to run.
After project creation and installation you can run the project in dev mode. In this mode, file changes will be automatically traced.
C:\node\projects\sample-project-name>sng dev
For production, you have to build first by the below command. After build one directory named "build" will be generated.
After that run sng start
to start the application.
C:\node\projects\sample-project-name>sng build
C:\node\projects\sample-project-name>sng start
Sample Code:
@AppConfiguration({
modules: [
{
id: "client",
apiDomainPath: '/api/client',
uiSourcePath: '/ui/client/WebContent',
uiServerPath: '/',
module: ClientModule
},
{
id: "admin",
apiDomainPath: '/api/admin',
isAdmin: true,
uiSourcePath: '/ui/admin/build',
uiServerPath: '/admin',
module: AdminModule
}
],
auth: CommonAuthService,
dbConnection: [DbConnection]
})
export default class Application {
public static main(arg: string[]) {
}
}
Here you are registering the modules
, auth
, database connection
and root paths of API
and UI
of the application.
Sample Code:
@AppModule({
controllers: [UserController, OwnerController],
services: [UserService],
dbCalls: [UserDbCall],
dtos: [UserDTO]
})
export default class ClientModule {}
Here you are registering controllers
, services
, database call
and dtos
of the ClientModule
.
Sample Code:
@ApiController({
path: "/user",
version: 0
})
export default class UserController {
@Autowired
userService: UserService;
//Get all list of user.
@ApiMapping({ path: '/list', method: HttpMethod.GET, produces: HttpHeader.Json })
getUserList(req: HttpRequest, res: HttpResponse) {
res.setStatusCode(200);
res.sendResponse({body: "Hello World!"});
console.log('in getUserList method!!!!!!!!!!!!!!!!!!!!!!!');
}
}
This is a controller class.
Sample Code:
@ApiMapping({ path: '/list', method: HttpMethod.GET, produces: HttpHeader.Json })
getUserList(req: HttpRequest, res: HttpResponse) {
res.setStatusCode(200);
res.sendResponse({body: "Hello World!"});
console.log('in getUserList method!!!!!!!!!!!!!!!!!!!!!!!');
}
Sample Code:
@ApiService()
export default class UserService {
@Autowired
userDbCall: UserDbCall;
}
Sample Code:
@DatabaseOperation()
export default class UserDbCall {
@Autowired
connection: DbConnection;
}
Sample Code:
@DatabaseConnection()
export default class DbConnection {
@EnvSettings("db")
dbSettings: EnvDbSettings;
}
Sample Code:
@ApiService()
export default class CommonAuthService {
@EnvSettings("data")
dataSettings: EnvDataSettings;
userBn: any = {
id: 1
}
@AuthMethod()
getAuthenticated(req: HttpRequest, res: HttpResponse, next: Function) {
console.log('in common Auth', req.moduleId);
//console.log(req, res, 'AuthService: ffffffffffffffffffffffffffffff')
next(this);
}
}
Sample Code:
@HttpInterceptor()
export default class AppMiddlewire implements Middlewire {
request: HttpRequest;
response: HttpResponse;
runSync(): boolean {
console.log('interceptor common::', this.request.moduleId)
return true;
}
}
Now you can hit the API with the below url:
http://localhost:8080/api/client/v0/user/list
http://localhost:8080/api/admin/v0/user
and UI:
http://localhost:8080
http://localhost:8080/admin