:relfileprefix: ../../../
[#boost-urls-url-2constructor-002]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url.adoc[pass:[url]]::url


Constructor


=== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url.hpp#L169[boost/url/url.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
explicit
url(core::string_view s);
----

=== Description


This function constructs a URL from
the string `s`, which must contain a
valid
_URI_
or
_relative-ref_
or else an exception is thrown.
The new url retains ownership by
allocating a copy of the passed string.
[,cpp]
----
url u( "https://www.example.com" );
----
[,cpp]
----
return url( parse_uri_reference( s ).value() );
----
[,cpp]
----
this->buffer().data() != s.data()
----

=== Linear in `s.size()`.

=== Calls to allocate may throw.

Exceptions thrown on invalid input.
[,cpp]
----
URI           = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

relative-ref  = relative-part [ "?" query ] [ "#" fragment ]
----

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-4.1[4.1. URI Reference]



=== Exceptions

|===
| Name | Thrown on

| `The`
| 
input does not contain a valid url.

|===



=== Parameters

|===
| Name | Description 

| *s*
| 
The string to parse.

|===




