Deno Developer

Deno Developer

1597876020

Web framework for Deno, built on top of Oak

Web framework for Deno, built on top of Oak

Currently in the works

  1. Dependency injection (delivered and usable! Improvements in the works)
  2. OpenAPI autogeneration of documentation
  3. CLI for autogeneration of Dactyl components

Available modules:

Currently, through mod.ts, you have access to (docs link on left):

  1. Controller.ts - function decorator responsible for assigning controller metadata
  2. Application.ts - application class able to register controllers, and start the webserver
  3. HttpException - throwable exception inside controller actions, Application will then handle said errors at top level and send the appropriate HTTP status code and message. There is also a list of included predefined HttpException classes, see below
  4. HttpStatus.ts - function decorator responsible for assigning default status codes for controller actions
  5. Method.ts - @Get, @Post, @Put, @Patch, @Delete function decorators responsible for defining routes on controller actions
  6. Before.ts - @Before method decorator responsible for defining actions to execute before controller action does. Has access to arguments as follows: @Before((body, params, query, headers, context) => console.log('do something!')

For following - Arg.ts

  1. @Param decorator maps context.params onto argument in controller action (returns whole params object if no key specified)

  2. @Body decorator maps context.request async body onto argument in controller action (returns whole body object if no key specified)

  3. @Query - maps context.url.searchParams onto argument in controller action (returns whole query object if no key specified)

  4. @Header - maps context.headers onto argument in controller action (returns whole header object if no key specified)

  5. @Context - return whole Oak RouterContext object

  6. @Request - return whole Oak Request object

  7. @Response - return whole Oak Response object

  8. @Inject - inject a dependency directly from DIContainer. specify key @Inject("DinosaurService")

  9. Router.ts - It is recommended that you use the Application to bootstrap, but you can use the Router class directly. This is a superclass of Oak’s router, and exposes additional methods for mapping Controller definitions onto routes.

For following - Injectable.ts

  1. @Injectable - tag a service as injectable. Supply a scope, e.g. @Injectable(EInjectionScope.SINGLETON)
  2. @AutoInject - tag a controller to use auto-injection of constructor params.

Purpose

Deno is the new kid on the block, and Oak seems to be paving the way for an express-like middleware and routing solution with our fancy new runtime. It’s only natural that abstractions on top of Oak are born in the near future - much like Nest tucked express middleware and routing under the hood and provided developers with declarative controllers, DI, etc. This project aims to provide a small portion of these features with room to expand in future.

Getting started

This repo contains an example project with one controller. You can execute this on your machine easily with Deno:

deno run --allow-net --config=tsconfig.json https://deno.land/x/dactyl/example/index.ts

One caveat is to ensure you have a tsconfig.json file enabling Reflect and function decorators for this project, as Deno does not support this in it’s default config. Ensure a tsconfig.json exists in your directory with at minimum:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

This should result in the following output:

______           _         _
|  _  \         | |       | |
| | | |__ _  ___| |_ _   _| |
| | | / _` |/ __| __| | | | |
| |/ / (_| | (__| |_| |_| | |
|___/ \__,_|\___|\__|\__, |_| FRAMEWORK
                      __/ |
                      |___/

/dinosaur
  [GET] /
  [GET] /:id
  [POST] /
  [PUT] /:id
  [DELETE] /:id

Dactyl running - please visit http://localhost:8000/

You can now visit your API.

Dactyl in action

In the above example project, there exists one Controller and a bootstrapping file, index.ts that starts the web server.

DinosaurController.ts Controllers are declared with function decorators. This stores metadata that is consumed on bootstrap and converted into route definitions that Oak can understand.

@Controller("/dinosaur")
@AutoInject()
class DinosaurController {
  constructor(private dinosaurService: DinosaurService) {}

  @Get("/")
  @HttpStatus(200)
  getDinosaurs(@Query("orderBy") orderBy: string) {
    const dinosaurs: Array<any> = this.dinosaurService.getAll();
    return {
      message: "Action returning all dinosaurs! Defaults to 200 status!",
      data: dinosaurs,
    };
  }

  @Get("/:id")
  getDinosaurById(@Param("id") id: string, @Header("content-type") contentType: string) {
    const dinosaur: any = this.dinosaurService.getById(id);
    return {
      dinosaur,
      ContentType: contentType,
    };
  }

  @Post("/")
  createDinosaur(
    @Body("name") name: any,
    @Inject("DinosaurService") dinosaurService: DinosaurService
  ) {
    if (!name) {
      throw new BadRequestException("name is a required field");
    }
    const newDinosaur: any = dinosaurService.addDinosaur(name);
    return {
      message: `Created dinosaur with name ${name}`,
      newDinosaur,
    };
  }

  @Put("/:id")
  @Before((body: any, params: any) => {
    if (!body.name || !params.id) {
      throw new BadRequestException("Caught bad request in decorator");
    }
  })
  @Before(
    async () =>
      await new Promise((resolve: Function) =>
        setTimeout((): void => {
          console.log("Can add async actions here too!");
          resolve();
        }, 2000)
      )
  )
  updateDinosaur(@Param("id") id: any, @Body() body: any) {
    return {
      message: `Updated name of dinosaur with id ${id} to ${body.name}`,
    };
  }

  @Delete("/:id")
  deleteDinosaur(
    @Context() ctx: RouterContext,
    @Request() req: OakRequest,
    @Response() res: OakResponse
  ) {
    res.status = 404;
    res.body = {
      msg: `No dinosaur found with id ${ctx.params.id}`,
    };
  }
}

export default DinosaurController;

DinosaurService.ts Dactyl supports dependency injection, and injects services via the constructor of Controller (see above). Supplied in the example is a service with scope SINGLETON, although TRANSIENT and REQUEST scopes are also supported. You can read more about dependency injection below.

@Injectable(EInjectionScope.SINGLETON)
export default class DinosaurService {
  #dinosaurs: Array<any> = [
    { id: 0, name: "Tyrannosaurus Rex", period: "Maastrichtian" },
    { id: 1, name: "Velociraptor", period: "Cretaceous" },
    { id: 2, name: "Diplodocus", period: "Oxfordian" },
  ];

  getAll(): Array<any> {
    return this.#dinosaurs;
  }

  getById(id: string): any {
    return this.#dinosaurs[parseInt(id, 10)];
  }

  addDinosaur(name: string) {
    const newDinosaur: any = {
      id: ++this.#lastId,
      name,
      period: "Unknown",
    };
    this.#dinosaurs.push(newDinosaur);
    return newDinosaur;
  }
}

index.ts This file bootstraps the web server by registering DinosaurController to the Application instance. Application can then use the .run() async method to start the webserver.

import { Application } from "./deps.ts";

import DinosaurController from "./DinosaurController.ts";
import DinosaurService from "./DinosaurService.ts";

const app: Application = new Application({
  controllers: [DinosaurController],
  injectables: [DinosaurService],
});

await app.run(8000);

And away we go. This spins up a web server using oak with the appropriately registered routes based on your controller definitions.

Configuration

There is additional configuration that you can pass to the application upon bootstrap:

const app: Application = new Application({
  controllers: [DinosaurController],
  config: {
    cors: false, // true by default
    timing: false, // true by default
    log: false, // true by default
  },
});
  1. cors - Enables CORS middleware (true by default). This sets the following headers to * on context.response: access-control-allow-origin, access-control-allow-methods, access-control-allow-methods.
  2. timing - Enables timing header middleware (true by default). This sets X-Response-Time header on context.response.
  3. log - Enables per-request logging (true by default). The message format is: 00:00:00 GMT+0000 (REGION) [GET] - /path/to/endpoint - [200 OK]

Dependency Injection

Dactyl uses it’s own dependency injection container. You can even access the API for the container itself from the dependency_container file exported in mod.ts. This container supports three scopes: SINGLETON, REQUEST, and TRANSIENT:

SINGLETON scoped dependencies are instantiated when the application starts up. When resolved from the container via autoinjection of constructor arguments, you will always receive the same instance that’s cached in the container. Use SINGLETON scope where possible.

REQUEST scoped dependencies are instantiated when a new request is received. When the request lifetime ends, the request dependency cache is dumped. If two concurrent requests are received by the Dactyl server, both requests will receive their own instance, even if they require the same dependency.

TRANSIENT scoped dependencies are instantiated every time they are resolved, meaning every controller or service that consumes a TRANSIENT dependency will receive it’s own instance.

Currently, Dactyl supports autoinjection of dependencies in the constructor, and parameter injection. In order to do this, the following must be done:

  1. Tag your service with the Injectable class decorator, with the scope you want:
@Injectable(EInjectionScope.TRANSIENT)
class DinosaurService {}
  1. Consume your service in the desired controller. It will be resolved by the container based on it’s type name. Be sure to tage the class with the @AutoInject decorator to auto inject constructor params.
@Controller("/dinosaur")
@AutoInject()
class DinosaurController {
  constructor(private dinosaurService: DinosaurService) {}
}
  1. Supply your Application class with the injectable, so that it may register it inside the container:
const app: Application = new Application({
  controllers: [DinosaurController],
  injectables: [DinosaurService],
});

And you’re all done! DinosaurService will be autoinjected into the constructor, with the TRANSIENT scope.

A Note on Scopes

One common design trap for Dependency Injection is parent dependencies depending on services with a smaller scope than their own. For example: Service A (Singleton) -> Service B (Request) Service A is only instantiated once, so how can it depend on a service that is instantiated every request? Some DI implementations will address this by making any service that is required by a singleton also a singleton, however this effectively negates the uses for TRANSIENT and REQUEST.

Instead Dactyl will perform a task (at resolution) to ensure that children dependencies do not decrease in size of scope, ensuring that the three scopes are being used properly. The scope size is as follows: Transient -> Request -> Singleton. And so the following is true:

Transient -> Request -> Singleton // will not throw error
Transient -> Transient // will not throw error
Request -> Request -> Singleton // will not throw error
Request -> Transient // will throw error
Singleton -> Request // will throw error

Exceptions

Exceptions can be raised at any time in the request lifecycle. HttpException allows you to raise a custom exception, or you can use a predefined HttpException (listed below):

  1. BadRequestException
  2. UnauthorizedException
  3. PaymentRequiredException
  4. ForbiddenException
  5. NotFoundException
  6. MethodNotAllowedException
  7. RequestTimeoutException
  8. UnsupportedMediaTypeException
  9. TeapotException
  10. UnprocessableEntityException
  11. TooManyRequestsException
  12. RequestHeaderFieldsTooLargeException
  13. InternalServerErrorException
  14. NotImplementedException
  15. BadGatewayException
  16. ServiceUnavailableException
  17. GatewayTimeoutException

HttpException.ts

Modules

All modules are accessible without the example project by referring to them in your deps.ts file. E.g.

export { Controller, DactylRouter, Get } from "https://deno.land/x/dactyl/mod.ts";

Download Details:

Author: liamtan28

Source Code: https://github.com/liamtan28/dactyl

#deno #nodejs #javascript #node

What is GEEK

Buddha Community

Web framework for Deno, built on top of Oak

Ajay Kapoor

1619172468

10 Top Web Development Frameworks for Assured Success of Your Project - PixelCrayons

Web development frameworks are a powerful answer for businesses to accomplish a unique web app as they play a vital role in providing tools and libraries for developers to use.

Most businesses strive to seek offbeat web applications that can perform better and enhance traffic to the site. Plus, it is imperative to have such apps as the competition is very high in the digital world.

Developers find it sophisticated to use the libraries and templates provided by frameworks to make interactive and user-friendly web applications. Moreover, frameworks assist them in increasing the efficiency, performance, and productivity of the web development task.

Before getting deep into it, let’s have a quick glance at the below facts and figures below that will help you comprehend the utility of the frameworks.

As per Statista, 35.9% of developers used React in 2020.
25.1% of developers used the Angular framework worldwide.
According to SimilarTech, 2,935 websites use the Spring framework, most popular among the News and Media domain.

What is a Framework?
A framework is a set of tools that paves the way for web developers to create rich and interactive web apps. It comprises libraries, templates, and specific software tools. Additionally, it enables them to develop a hassle-free application by not rewriting the same code to build the application.

There are two categories of frameworks: the back-end framework, known as the server-side, and the front-end framework, known as the client-side.

The backend framework refers to a web page portion that you can not see, and it communicates with the front end one. On the other hand, the front-end is a part of the web that users can see and experience.

You can understand by an example that what you see on the app is the front-end part, and the communication you make with it is the part of the back end.

Read the full blog here

Hence, depending on your web development application requirements, you can hire web developers from India’s best web development company. In no time, you will be amongst those who are reaping the results of using web development frameworks for the applications.

#web-development-frameworks #web-frameworks #top-web-frameworks #best-web-development-frameworks

Any Alpha

Any Alpha

1613122689

Top 3 Golang Web Frameworks In 2021

Golang is one of the most powerful and famous tools used to write APIs and web frameworks. Google’s ‘Go’ otherwise known as Golan orders speedy running local code. It is amazing to run a few programming advancements rethinking specialists and software engineers from various sections. We can undoubtedly say that this is on the grounds that the engineers have thought that it was easiest to utilize Go. It is always considered as ago for web and mobile app development because it is ranked highest among all the web programming languages.

Top 3 Golang web frameworks in 2021:

1.Martini: Martini is said to be a low-profile framework as it’s a small community but also known for its various unique things like injecting various data sets or working on handlers of different types. It is very active and there are some twenty and above plug-ins which could also be the reason for the need for add-ons. It deals with some principles of techniques like routing, dealing, etc, basic common tricks to do middleware.

2.Buffalo: Buffalo is known for its fast application development services. It is a complete process of starting any project from scratch and providing end to end facility for back-end web building. Buffalo comes with the dev command which helps directly to experience transformations in front of you and redevelop your whole binary. It is rather an ecosystem used to create the best app development.

3.Gorilla: Gorilla is the largest and longest-running Go web framework. It can be little and maximum for any user. It is also the biggest English-speaking community that comes with robust web sockets features so you can attach the REST codes to the endpoints giving a third-party service like Pusher.

So, these are some web frameworks that can be used for Golang language. Each framework has its unique points which are only found in them but all of them are the best. IF your developer is in search of one this is where you can find the best.

#top 3 golang web frameworks in 2021 #golang #framework #web-service #web #web-development

Top Responsive Web App Development Company in USA

AppClues Infotech is a well known web application development company. We help you to redefine your technological environment in this constantly changing digital age and competitive scenario. We specialize in developing customer centric web applications and provide you with enhanced web app development services as well as modern app marketing services which are focused to drive effectiveness and efficiency to your business.

We have team of creative website developers, designers, testers and quality engineers help businesses to operate their day-to-day activities actively. We serve superb app design & development services with great ease and awareness. With our responsive website design services, we provide user-friendly experience across all platforms (desktop, tablet, mobile).

Want A Beautiful Web App? We build 100% Responsive, Mobile Friendly, Professionally designed websites Loved By Clients & Google.

For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910

#top responsive web app development company in usa #top web development companies in united states #best web development company usa #web application development company usa & india #web app development company in new york #top web app development company

Top 10 Web Application Frameworks

From a wide variety of Web Application Development Frameworks, it is eternally tough to pick the one framework that is completely satisfied with the project. Here, Top 10 Web Application Frameworks Describe in detail.

#web application frameworks #top web application frameworks #server-side web frameworks

Top 15 Free JavaScript Frameworks for Web Applications

List of some useful JavaScript Frameworks and libraries for website, web apps, and mobile apps development, that developers should know about to make selection easier.
This article will help you understand the various types of JavaScript Framework available in the market. When it comes to choosing the best platform for you, it’s not only the number of features you need to consider but also its functionality. The ease with which it fits within your project is also an essential factor. The next step is to choose the framework that best fits your company requirements or you can select the best from the list of top web development companies to develop your product based on your requirements.

#javascript frameworks for web applications #web applications development companies #progressive javascript framework #javascript frameworks #javascript #frameworks